My functions change various aspects of a given text. For the following text:
I am young. You are young.All of us are young.
"I think we need some help.Please" HELP. NO, NO NO,
I DO NOT
NEED HELP
WHATSOEVER.
"Today's date is
15/02/2021"...
I am 18 years old. are you 20 years old? Maybe 30 years?
I need it to be prints like this:
I am young. You are young.All of us are young.
"I think we need some help.Please" HELP. NO, NO NO,
I DO NOT
NEED HELP
WHATSOEVER.
"Today's date is
15/02/2021"...
I am years old. are you years old? Maybe years?
For some reason, I have a problem with deleting the numbers and keep in the same state I was prevoisly. this is my code:
main(){
int state,c,cnt,state1;
cnt=0;
state = OUT;
state1=COUNTINUE;
printf("PLease insert a sentence\n");
while((c=getchar())!=EOF){
if(isDigit(c)==TRUE) {
printf("\b");
}
if (c=='.')
{
putchar(c);
state =OUT;
}
if (c=='"')
{
state = IN;
cnt+=1;
}
if(cnt==1)
state =IN;
if(cnt==2)
{
cnt=0;
putchar(c);
state = OUT;
}
if(state == OUT &&isChar(c)==TRUE ){
if(isUpper(c) ==TRUE)
putchar(c);
else
putchar(toUpper(c));
state = COUNTINUE;
}
else if(state==COUNTINUE)
if(isUpper(c)==FALSE)
putchar(c);
else
putchar(toLower(c));
else if(state ==IN &&c!='.' &&isDigit(c)==FALSE)
if(isUpper(c)==FALSE)
putchar(toUpper(c));
else
putchar(c);
}
}
This is the output Im given:
I am young.You are young.All of us are young."I THINK WE NEED SOME HELP.PLEASE"Help.No, no no,
i do not
need help
whatsoever."TODAY'S DATE IS
"...I am8 years old.Are you0 years old? maybe 0 years?
Looking at the input and required output, I don't understand why would you use toUpper()
and toLower()
functions. Anyway, your approach is wrong. The below code is enough to skip digits.
while((c=getchar())!=EOF){
if(isDigit(c)==true){
continue;
}
putchar(c);
}
Now, I assume you want to print digits in ""
ie double quotes. In required output it's 15/02/2021
. For that, you would need to use a flag
. Set flag=1
if you encounter c='"'
which indicates we are inside the ""
ie double quotes. If we encounter another c= '"'
which indicates end of double quote pair, we set flag=0
. The below code prints digits when inside ""
.
flag=0;
while((c=getchar())!=EOF){
if(c=='"'){
flag=!flag;//swapping 0 and 1
}
if(isDigit(c)==true && flag==0){
continue;
}
putchar(c);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.