I use a
scanf("%d%d",&row,&col); // row & col is int
before
fgets(buf, MAXLEN, stdin); //MAXLEN == 65535 ; buf is char
I want to input buf after input row and col
but fgets will be skip
May someone help me?
I use a
scanf("%d%d",&row,&col); // row & col is int
before
fgets(buf, MAXLEN, stdin); //MAXLEN == 65535 ; buf is char
I want to input buf after input row and col
but fgets will be skip
May someone help me?
This issue can arise if your input is on two separate lines. scanf()
will leave a newline character in the buffer; when fgets()
tries to read the remainder of the input, it will receive the newline character and stop reading. The following may fix your code:
scanf("%d%d\n", &row, &col);
This will read the newline in as well, leaving the rest for fgets()
.