Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define LIMIT 100
- char converte(char c , int shift)
- {
- c += shift ;
- if (c > 'z') c = ('a' - 1) + (c - 'z') ;
- else if (c < 'a') c = ('z' + 1) - ('a' - c) ;
- return (c) ;
- }
- void desloca(char texto[] , char cifra[] , int shift)
- {
- int i ;
- for (i = 0 ; i < strlen (texto) ; i++)
- {
- if (isalpha(texto[i])) cifra[i] = converte(texto[i] , shift) ;
- else cifra[i] = texto[i] ;
- }
- cifra[strlen (texto)] = '\0' ;
- }
- void main()
- {
- char txt[LIMIT] , cifra[LIMIT] ;
- int shift ;
- printf ("Texto? ") ;
- fgets (txt , LIMIT , stdin) ;
- printf ("Shift? ") ;
- scanf ("\n%d" , &shift) ;
- desloca (txt , cifra , shift) ;
- printf ("Cifra: %s\n" , cifra) ;
- }
Advertisement
Add Comment
Please, Sign In to add comment