I've been working on a problem. I need to scan for a \n
to end the cycle and delete it to not remain in a variable with other text. So far I have this:
do {
scanf("%[^\n]", userinput); //loads stdin to char[] variable
end = userinput[0]; //loads one char to char variable
scanf("%*c"); //should remove \n
strcpy(inputstorage[i], userinput); //copies userinput into 2d array of
i++; //string with \n removed
} while (end != '\n'); //should end cycle when I hit enter
What this does is, when I press enter it keeps the last char in the variable end.
For example I enter: 'Hello
'
In userinput
is: 'Hello
'
In end
is 'H
'
When I hit enter afterwards the end variable should contain \n but it contains 'H
' for some reason. I appreciate all the help you can provide