for (int i = 0; i < argv[1][i]; i++)
{
if (isalpha(argv[1][i]))
{
if (argv[1][i] >= 'A' && argv[1][i] <= 'Z')
{
int shift = argv[2][i] - 65;
printf("%c + %c '%.3d' == ", argv[1][i], argv[2][i], shift);
char rightNumber = argv[1][i] + shift;
if (rightNumber > 'Z')
rightNumber -= 26;
printf("%c\n", rightNumber);
}
}
}
#include <string.h>
#include <stdio.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
int incode_len = strlen(argv[1]);
int key_len = strlen(argv[2]);
for (int i = 0, k = 0; i < incode_len; i++, k++)
{
if( k >= key_len) k = 0;
if (isalpha(argv[1][i]))
{
if (argv[1][i] >= 'A' && argv[1][i] <= 'Z')
{
int shift = argv[2][k] - 65;
printf("%c + %c '%.3d' == ", argv[1][i], argv[2][k], shift);
char rightNumber = argv[1][i] + shift;
if (rightNumber > 'Z') rightNumber -= 26;
printf("%c\n", rightNumber);
}
}
}
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
const char *s, *start, *end, *cur;
int n, i;
if (argc == 3) {
s = argv[1];
n = atoi(argv[2]);
} else {
s = "12345";
n = 50;
}
start = end = s;
if (*end)
while (*(end + 1))
end++;
cur = start;
for (i = 0; i < n; i++) {
putchar(*cur);
cur = (cur < end) ? cur + 1 : start;
}
putchar('\n');
return 0;
}
[guest@localhost c]$ .ansi t.c -o t
[guest@localhost c]$ ./t
12345123451234512345123451234512345123451234512345
[guest@localhost c]$ ./t abc 80
abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab
[guest@localhost c]$ ./t a 10
aaaaaaaaaa
[guest@localhost c]$ ./t ab 10
ababababab
[guest@localhost c]$ ./t abc 10
abcabcabca
[guest@localhost c]$
#include <string.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned char *text, *key;
unsigned char shift, rightNumber;
for (text = argv[1], key = argv[2]; *text; text++, key++) {
if (0 == *key)
key = argv[2];
if (*text >= 'A' && *text <= 'Z') {
shift = *key - 'A';
rightNumber = *text + shift;
if (rightNumber > 'Z')
rightNumber -= ('Z' - 'A');
printf(""%c + %c '%.3d' == "%c\n", *text, *key, shift, rightNumber);
}
}