Continue while loop until char == EOF
while( (c = fgetc(stdin)) != EOF ){
count++;
if (count == lineLen - 1){
moreChars = (char*) realloc(line, lineLen *=2);
if(moreChars == NULL){
puts("Error allocating for moreChars.");
free(moreChars);
exit(-69);
}
else
line = moreChars;
}
line[count - 1] = c;
}
This is my code. My problem is that when the user enters (ctrl + d) to end the loop, he has to enter it twice, i.e. To terminate custom loop types (ctrl + d) (ctrl + d).
sample input:
Hey you dood guy (ctrl + d) (ctrl + d)
ideal entrance:
Hey you dood guy (ctrl + d)
To make it clearer:
I want the user to only have to enter (ctrl + d) once to end the loop and cannot figure out why the use should enter (ctrl + d) (ctrl + d) at the end of the loop.
Thank.
+3
source to share