I wrote the following code:
int N;
scanf(\"%d\", &N);
int i;
for (i = 0; i < N; i++) {
char line[LINE_MAX];
if (fgets(line, LINE_MAX, stdin) != NU
It has nothing to do with threading. scanf()
reads exactly what you ask it to; it's leaving everything else unread, notably the newline following the data. (You also aren't dealing with the possibility that the user didn't type what you intended.)
If you want to do line oriented input, use fgets()
. Don't use scanf()
and hope the system can magically intuit that you want to ignore what you didn't read.