The below code tries to manipulate several lines of text one at the time.
1.My first issue is to write a loop to read several lines of text(using scanf()) and quit when the first character typed is a newline. These lines of text have some conditions: The first character must be a number between 2 and 6 followed by a space and a line of text(<80).This number will make "dance" the text.
2.My second issue is to figure out how to convert the letters from small to capital and viceversa according to the first number typed. I have to function to make these conversions but I don't know how to call them to change the text.For example: if I typed "3 apples and bananas" the correct output should be "AppLes And BanNas".As you see, the white spaces are ignored and the text always start with a capital letter.
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <ctype.h>
using namespace std;
void print_upper(string s1);
void print_lower(string s2);
void main(void)
{
char text[80];
text[0]='A';//Initialization
int count_rhythm;
while (text[0] != '\n'){//To make the loop run until a newline is typed
scanf(" %79[^\n]",text);
if(isdigit(text[0])) //To verify that the first character is a number
{
printf("\nGood");//Only to test
}
else
{
printf("\nWrong text\n");//Only to test
}
}
}
void print_upper(string s1)//Print capital letters
{
int k1;
for(k1=0; s1[k1]!='\0'; ++k1)
putchar(toupper(s1[k1]));
}
void print_lower(string s2)//Print small letters
{
int k2;
for(k2=0; s2[k2]='\0'; ++k2)
putchar(tolower(s2[k2]));
}