Hey everyone, just found these forums and they seem to be the most active C forums I've found. I'm fairly new to programming and have a quick question about strings. If I want to ask the user for input using scanf, and the user input has spaces, what is the best way to deal with that?
Example (Doesn't work but I thought it should)
Code:
scanf("%s",string);
printf("The string entered is: %s,string);
User inputs: "Hi this is a string"
Output: "Hi"
Example (Works but doesn't like the best way)
Code:
scanf("%[^\n]",string);
printf("The string entered is: %s,string);
User inputs: "Hi this is a string"
Output: "Hi this is a string"
So I can get it to work using %[^\n], which to my knowledge basically tells the scanf to not stop taking input if a space is found. So can a simply Scanf(%s) not take spaces or whitespace?