#string not reading all the words

15 messages · Page 1 of 1 (latest)

vast heronBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

bright mirage
#

firstly, format your code

#

it will help you

#

second:

#

!debugger

vast heronBOT
# bright mirage !debugger

Have you tried stepping through your code line by line in a debugger?

If you don't know how to use a debugger or don't have one set up, we highly recommend taking the time to do so.
Debuggers are immensely helpful tools for figuring out where problems emerge in code and especially when you're first learning it can help you build intuition and understanding for reasoning through code.

Resources:

floral crane
#

scanf only reads a string to the first space, if you want all typed words to be read you'll either need to call scanf multiple times or use something else. What trouble did fgets cause you?

eager pelican
#

fgets() should definitely work.

#

;compile | "one two three"

#include <stdio.h>
#include <string.h>

int main()
{
    char input[100];

    fgets(input, sizeof input, stdin);
    input[strcspn(input, "\n")] = 0;

    puts(input);
}
wheat lindenBOT
#
Critical error:

You are sending requests too fast!

eager pelican
#

Typical

limpid pelican
#

scanf("%s", str) only reads to the first whitespace

#

that includes the space character

#

so you have to tell it to either read a whole line, or read 2 "words"(obviously only works if a person has 2 names)

vast heronBOT
#

@wind rapids

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.