Notwithstanding what you do with the data you read, if you do not consume any data from the standard input between the two scanf
calls presented then yes, it is to be expected that the second will not consume or convert any additional input. That is because after the first ...
scanf("%[^\n\r]", inStr);
..., if there are any more characters available from the standard input then the next is either a newline or a carriage return (supposing, of course, that the behavior does not end up being undefined on account of overrunning the bounds of inStr
). Unlike most scanf
field directives, %[
does not skip leading whitespace, so if at that point you perform ...
scanf("%[^\n\r]", inStr);
... again then the first character encountered, if any, is that same carriage return or line feed, which is (again) excluded from the scan set. The scanf
call therefore terminates without consuming or converting any characters. It will return 0 or EOF
depending on whether in fact there are any characters available to read.
Laying aside the grave risk of a buffer overflow, you need to consume at least one character between the two scanf
calls to give the second and subsequent ones a chance to read anything, or else to insert a leading space character into your scanf
formats to get the skip over leading whitespace that %[
does not perform automatically. Moreover, you need to check the return value of every scanf
call to determine whether it successfully converted any data, and whether there is any point in trying to consume more via subsequent calls.