Simple question (I think), in C, I was able to scan in an entire line using:
fgets(line, MAX, input);
printf("%s\n", line);
Where it would, for example, print “Please cut me in half”, how do I only get “me in half”, including white spaces.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You do not know where the middle is until you scan the whole line. But you can scan the entire line, and then print only the second half, like this:
This is how the above code works:
strlendetermines the length of the entire string (21), then we divide it in half using integer division (10), add it to the pointer to the beginning of the line, and pass the result toprintf.