Skip to content

Instantly share code, notes, and snippets.

@fabiommendes
Last active October 13, 2021 15:14
Show Gist options
  • Save fabiommendes/92898922f022acd1da2bc85f3e1f84e0 to your computer and use it in GitHub Desktop.
Save fabiommendes/92898922f022acd1da2bc85f3e1f84e0 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
#include <string.h>
/**
* Aplica a cifra de César na string de entrada.
*
* Modifica o argumento durante a aplicação.
*/
void cesar(char *msg)
{
int n = strlen(msg);
for (int i = 0; i < n; i++)
{
char c = msg[i];
if (c >= 'a' && c <= 'z')
{
msg[i] = (c + 3 - 'a') % 26 + 'a';
}
if (c >= 'A' && c <= 'Z')
{
msg[i] = (c + 3 - 'A') % 26 + 'A';
}
}
}
int main()
{
char msg[101];
int n = 42;
fgets(msg, 100, stdin);
cesar(msg);
printf("%s\n", msg);
printf("%d\n", n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment