Get all the text from a typed line

Asked

Viewed 385 times

-2

I am creating a C algorithm to train even and need to pick a text (large and with spaces) that the user type at the same prompt. I tried using scanf, gets and fgets and none is picking up what comes after space, just the text until you get into the first space. How I can grab all the text and save in a char array only ?

char texto[3000];
fgets(texto, 3000, stdin);

My last attempt was this, but it only takes the first word before space.

Note that you cannot get enter (line break) because there are more actions to be done after picking up the first text

  • 1

    I tested here and picked up the words after the space

1 answer

3

I did this test here and it read the whole line. How are you checking the value read? It may be that the error is in this part.

Look at my code:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char texto[3000];
    fgets(texto, 3000, stdin);
    printf("%s", texto);

    return 0;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.