christieeveleigh0@gmail.com
Simple Programming: rot_13.c

Rot 13 is a character substitution, replacing an alphabetical character with the 13th letter after it. This fun program could be used to send coded messages or puzzle solutions. It could also be used to encode email addresses to hide them from spam bots. We’re using arguments today (int ac, char *av[]).

Don’t forget to include the unistd.h library so you can use the write() function. Copy rot_13.c into your terminal and give it a try!


int main(int ac, char *av[])
{
int i;
int c;
int d;
i = 0;

if(ac == 2)
{
while(av[1][i])
{
if(av[1][i] >= 'a' && av[1][i] <= 'y') { c = av[1][i] + 1; write(1, &c, 1); } else if(av[1][i] == 'z') { d = av[1][i] - 25; write(1, &d, 1); } else { write(1, &av[1][i], 1); } i++; } } write(1, "\n", 1); return (0); }

© Christie Eveleigh Marx 2020

× How can I help you?