I’m trying to see if when I do
fscanf(inputSTREAM, "$%s$", out)
I can also return the $ signs – is there a way?
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.
I don’t think there’s a way to retrieve the string with the dollar signs and the non-blank string between them using the
scanf()family of functions. The closest approach would probably be using a scanset, but scansets are not the same as regular expressions, and you’d need a regular expression to specify the pattern you are looking for.In practice, you could probably get the first dollar sign into the string using:
You can’t pull the same stunt for the latter dollar sign, even if you know the exact length of the string. The trouble is that you’d need to overwrite the null at the end of the string with the second dollar sign, and you’d want a NUL
'\0'after the string. Adding the final dollar is much easier than inserting the first at the beginning of the string. The third scanset contains an assignment-suppressing ‘*‘ and requires a dollar at the end. The leading space in the format skips spaces.This isn’t guaranteed behaviour; the first conversion would write a NUL over
out[1], and the second conversion would then write the string overout[1], but the C standard does not guarantee that it will work.