I’m having a problem with scanf freezing. I’ve looked around and while some questions are similar, they haven’t helped in solving my problem.
main(int argc, char **argv) {
//FILE *stream = stdin;
if (stdin == NULL) {
printf("Could not open file");
return 0;
}
int exists = 0;
char letter;
char next = 'H';
char word[30];
int frequency = -1;
int sample = -1;
char *channels;
channels=malloc(sizeof(7*sizeof(char)));
int bitres = -1;
int secondE = 0;
while (exists == 0) {
scanf("%c", &letter); //this is the problem, possibly scanf
printf("AFTER");
if (letter == EOF) {
// printf(letter);
printf("HEADER NOT DETECTED");
return 0;
}
I’ve pinpointed the problem using printf. I’m currently piping in another file through command prompt into this program. When I reach scanf it just hangs. If anyone knows the solution I would be very thankful.
On a side note, is using scanf bad practice? It’s just as easy to assign stdin to a file pointer (I actually have this commented out) but scanf seemed just as easy.
what do you mean by freezing. i run this code. when your code reach in
scanfit wait for your input. you give some input , then see what happen.scanf is not a bad practice .
scanf never return EOF also.