C Reading String with Spaces : Using scanf()



Reading String with spaces by using scanf
Note that –

  1. scanf with %s accepts only String which does not contain whitespaces (blanks/space)
  2. C Supports the ‘ special Edit set Conversion Code ‘ , by using this method we can accept the line of String with spaces using scanf
  3. It Reads wide verity of Characters including blank

Syntax :

scanf("%[\^n]", name );

Live Example : 

char name[100];

printf("\nEnter the name : ");
scanf("%[\^n]",name);

printf ("\nName of Student : %s ",name);

Output of this Block :

Enter the Name : Don Bosqo
Name of Student : Don Bosqo