Kunhi
-3
Q:

how to get a string in c with space

#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;
}
0
#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;
1
#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);
}
0

New to Communities?

Join the community