0

how do I insert into a variable a text input from the user including white spaces? I'm trying to write a function to calculate characters in a text input but when I create the array the variable only takes the first word and the rest is ignored.

Here is my code:

int main(void){
    char text[100]; 

    printf("Enter some text:\n");
    scanf("%s", text);

    printf(text);
    printf("\n%i", strlen(text));
}

This works only if the user inputs one word but I would like my code to be able to take the user's full input including white spaces. Thanks for your help!

Tijo
  • 3
  • 2
  • It's best to use `fgets` if you want to read a line of text. Be aware that `fgets` puts the newline character in the buffer. Here's information on [how to remove the newline](https://stackoverflow.com/questions/2693776). – user3386109 Nov 30 '22 at 22:53

0 Answers0