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.
15 messages · Page 1 of 1 (latest)
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.
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:
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?
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);
}
Typical
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)
@wind rapids
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.