how to get a string in c with space
snippet in c
how to store a user input with spaces in c
user1048
#include <stdio.h>
int main(){
char name[20];
printf("Enter a name : ");
scanf("%[^\n]%*c", &name);
printf("the name entered is: %s\n", name);
return 0;
}
how to get a string in c with space
user8504
#include <stdio.h>
// program to get a full name
int main(){
char input[100];
printf("Please Enter Your Full Name: ");
scanf("%[^\n]%*c", text);
//%[] is a scanset, which allows scanf to skip scanning certain characters
//Therefore %[^\n] tells scanf not stop scanning until the next line occures
// and %*c tells scanf to use this c as a representative of the new line.
// the "*" tells scanf to delete the temporary newline character.
//read more in the link provided
printf("Your Full Name Is: %s\n", text);
}
how to store a user input with spaces in c
user548
#include <stdio.h>
int main(){
char name[20];
printf("Enter a name : ");
fgets(name, 20, stdin); // fgets(variable_storing_to, accepted_input_size, stdin)
printf("the name entered is: %s\n", name);
return 0;