Multi-Word Strings
Explore different methods for traversing multi-word strings in C.
Input a multi-word string using scanf()
If a multi-word string is supplied to scanf(), only the first word gets stored in the array, str3.
#include<stdio.h>
int main(){
char str3[15];
printf("Enter name & surname\n");
// Get multiword string using %s specifier
scanf("%s", str3);
printf("%s\n", str3);
}To overcome this, we need to use the format specifier, “%[^\n]s”. This means that the program will receive all the words in the string, from the beginning up to a \n ...
Ask