I'm new to C programming, and I was asked to create a simple line filter, (In Stdin), and print it again in stdout (without saving the whole sentence) and except for one line ("\ n") if "@" or "*" is typed (also I want every sentence to begin with its line number) I completed the program and it is a small It works very well except for something: I lose the first letter for every input I was required as the rest.
Can anyone tell me what is wrong?
#include & lt; Stdlib.h & gt; # Include & lt; Stdio.h & gt; #include & lt; String.h & gt; Int main (int argc, char ** argv) {char cinput; Int i = 1; Int moreData = 1; Printf ("line_splitator, please enter a sentence: \ n"); Fflush (stdout); Cinput = fgetc (stdin); Printf ("% c:", i); I = I + 1; / * Error * / When the file does not end to avoid, while (! Feof (stdin) & more data) {cinput = fgetc (stdin); Fputc (cinput, stdout); Switch (cinput) {case '@': case '*': printf ("\ n"); Printf ("% d:", i); I = I + 1; break; Case '\ n': more data = 0; Default: Break; }} Printf ("\ ndone! \ N"); Return 0; }
Edit: Thank you, I created it :)
After using fflush
immediately, you read a character. The character is never printed / processed
and then update the loop of its time, while extracting (cinput = fgetc (stdin))! = EOF & amp; More data Ensure that you want to repeat cinput as int
which is the correct redirect type fgetc.
No comments:
Post a Comment