christieeveleigh0@gmail.com
Simple Programming : Repeat_alpha.c

Today I’m excited to show you a fun C program I wrote that takes a string and display it repeating each alphabetical character as many times as its alphabetical index. It must be followed by a newline. There are a few limitations: I can’t use printf() and I must use arguments.

Don’t forget to include the unistd.h library. Copy repeat_alpha.c into your terminal and give it a try!

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

if(ac == 2)
{
while(av[1][i])
{
if(av[1][i] >= 'a' && av[1][i] <= 'z')
{
j = av[1][i] - 97;

while(j >= 0)
{
write(1, &av[1][i], 1);
j--;
}
}

else {
write(1, &av[1][i], 1);
}

i++;
}
}

write(1, "\n", 1);
return (0);
}

© Christie Eveleigh Marx 2020

× How can I help you?