Hi, there this one lab tutorial i need to do:
The question goes like this :
The program prompts the user to enter each line of text and does the conversion when the
text is entered. When an asterisk is entered, the program terminates. Assume that only
lowercase characters and space are entered.
Example execution (input text in italics):
Please enter text line: lord of the rings
LORD OF THE RINGS
Please enter text line: star wars
STAR WARS
Please enter text line: money no enough
MONEY NO ENOUGH
Please enter text line: *
Have a good day.
Ive done my program.
Here it is :
The problem is, when i try to loop the program so that it will keep inquire the user to enter new text, it seems that my buffer doesn't get flushed. Means that if i enter a it will converts to A, and when the next line comes and i enter b, it will show AB. I tried flushall(), it doesn't work.Code:#include <stdio.h> #include <ctype.h> #include <string.h> main () { char c, sentence[80]; int i=0 ,array=0; while ( c != '*') { puts ("\n\nEnter a line of text :"); while ( ( c = getchar () ) != '\n') sentence[i++] = c; sentence[i] = '\0'; puts("\nThe Converted Text is:"); while (array != (strlen (sentence) )) { sentence[array] = toupper ( sentence[array] ); array++; } puts(sentence); } getchar(); }
Second, when i loop with while ( c = ! '*'), it just doesn work, it won't terminate even when i enter asterisk (*).
Can anyone help me !!!!!!!!!!!!!!!!



LinkBack URL
About LinkBacks



