I am new at C programing, and i was asked to build a simple line splitter, that receives a sentence input from the user (in the stdin), and print it again in the stdout (without saving the whole sentence) and skips one line ("\n") if "@" or "*" were typed in. (also they want each sentence to start with its line number). I completed the program and it works great, except one little thing: for every input I try the first letter is lost. the rest is done as I was required.
can anyone tell me what is wrong?
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
char cInput;
int i = 1;
int moreData = 1;
printf( "line_splitter, please enter a sentence:\n");
fflush(stdout);
cInput = fgetc(stdin);
printf("%c: ", i);
i=i+1;
/*while not end of file read to avoid error*/
while(!feof(stdin) && moreData){
cInput = fgetc(stdin);
fputc(cInput,stdout);
switch(cInput){
case '@':
case '*':
printf("\n");
printf("%d: ", i);
i=i+1;
break;
case '\n':
moreData = 0;
default:
break;
}
}
printf( "\ndone!\n");
return 0;
}
EDIT: thank you all, i made it :)