1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include <stdio.h>
void cesar (char *str, int decalage)
{
if (str)
{
const char alphabet[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z'};
int maj = 0;
while (*str)
{
int i;
maj = isupper (*str);
*str = tolower (*str);
for (i = 0; i < 26; i++)
{
if (alphabet[i] == *str)
{
*str = alphabet[(i+decalage)%26];
if (maj)
{
*str = toupper (*str);
}
break;
}
}
str++;
}
}
}
void main (void)
{
char *text;
int decal=3:
gets (text):
cesar (text,decal);
puts (text);
} |
Partager