It completely stops reading in code after it sees a space. How do I change my code so it reads in white space
char line[300];
printf("Enter a string to be checked: ");
scanf("%s", line);
the string I'm trying to input via redirection is:
( ( a a ) < > [ [ [ { [ x ] ]]] <>)
you should use
fgets(line, size, stdin);
as previously posted. you should never usegets()
, as it expects a the same input size every time. Compilers, at least gcc, will warn you not to use it.%s Matches a sequence of non-white-space characters; the next pointer must be a pointer to char, and the array must be large enough to accept all the sequence and the terminating NUL character. The input string stops at white space or at the maximum field width, whichever occurs first.
Need to choose a different format string. It's not really clear from your input string what exactly you're trying to accomplish.
You can use fgets intsead of scanf. For example:
Please check the code..
Output:-