Hey guys so I am trying to do the following:
I have a string of the form and the _ are actually spaces.:
__ 1 ____Multithreaded Programming :: Improving Performance through Threads
I want to read the integer without spaces, and then read the remainder of the string including the space that will be in front of the string.
I have the following code:
while(fgets(line, MAX_STRINGS, stdin)){
sscanf(line, "%d %88[^\n]s", &num, string_value);
printf("%d + %s\n", num, string_value);
}
It reads the integer and also it reads the rest of the string ( My requirements for the problem state that the whole string including the integer will not be more than 88 bytes) BUT it ommits all the spaces in front of the string and I need them. How can I keep the white spaces? Thanks!
Remove the space between %d and %88. A space in the sscanf
format string means "consume and discard all whitespace".