"%s" is the default parsing format of a string in scanf(). "%s" does not include blanks or tabs etc. Here we need an end of sentence character like full stop or $ or new line (\n) to tell scanf() that we are at the end of an input. Some compiler also supports "%[...]" to scan blanks and tabs in the string. Let us see an example where user types in a sentence and gives full stop at the end.

Example Code:
int main(int argc, char *argv[])
  char string[20];
  printf("Enter the sentence, end with full stop or dot \n: ");
  scanf("%[^.]", string);

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

ternary operator, fprintf, fscanf working principal, printing pointers, scanf string input, scan string with blanks, scanf string ends with newline, return of scanf, return of printf, scanf with printf,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan