how to take a string with white spaces in c???

how to take a string input with white spaces in c???

You could use :

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

This will get a string till a new line is encountered. Or you could instead use

fgets(string, len, stdin)

Here len is the number of characters you want to read.
However using fgets will also store a new line character at the end!

You can use gets() function.

It can receive a multi-word string.

gets example

#include <stdio.h>

int main()
{
  char string [256];
  printf ("Insert your full address: ");
  gets (string);
  printf ("Your address is: %s\n",string);
  return 0;
}
1 Like

gets() can be used for only character arrays not strings