I am writing a program where the user inputs a string and have to make the string "dance" based on a rhythm they also input.
rhythm 2 : *_*_*_*_ etc.. (where star is capitalized and _ is lower case)
This is my code so far:
Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main (void)
{
char line[100];
int rythym;
char *p;
int k =0 ;
printf("Enter a string:");
gets(line);
printf("Enter a rythym:");
scanf("%d", &rythym);
printf("Original String: %s\n", line);
for (p = line; *p != '\0'; p++)
{
*p = toupper(*p);
}
while(line[k] != '\0')
{
if(rythym == 2)
{
line[k] = tolower(line[k]);
k+= rythym;
}
}
printf("After rythym applied: %s\n\n", line);
return 0;
}
Code:
Output:
Enter a string:Hello World make me dance
Enter a rythym:2
Original String: Hello World make me dance
After rythym applied: hElLo wOrLd mAkE Me dAnCe
I still have two things to address:
I need the first word to always be capitalized and I also need to not count whitespaces for the rhythm.
So my output needs to look like this:
"HeLlO wOrLd MaKe Me DaNcE"
I have an idea as to how to make the first word always capitalized but I need tips or advice on not applying the rythym for whitespace.
Thanks so much in advance