Question

To suppress newline we use %[^\n]. Can you suggest what should be the format to skip blank in the input, i.e. if we have to input "hallo stackflow". I know fgets and gets but i don't want to use them, they are creating problem.

Was it helpful?

Solution

Put a blank in the scanf format; that suppresses whitespace.

OTHER TIPS

I think you mean "include whitespace". Use:

#define str(x) #x
#define xstr(x) str(x)
/* ... */
char buf[ SIZE + 1 ] = "";
int rc = scanf("%" xstr(SIZE) "[^\n]%*[^\n]", buf);
/*you may need the return value later on, if reading
  in multiple strings with whitespaces in a loop */
if (!feof(stdin)) 
     getchar(); /* consume newline */
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top