Program is as below :
Code is :
char str; // Declaring the char array you can change the size according to the problem.
printf(“Enter a line of text : “);
scanf (“%[^n]s”, str); // Taking string input %[^n]s is used to take input with spaces.