I want to read data from a string. The string is like this:
"123 35 123 0 0 0 817 0 0 0 0"
there are a few numbers and spaces which is uncertain in the string. I want to read the third number. How to read data?
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.
Use
sscanf(). It will skip whitespace.You can also use
%*to suppress assignment of the two first numbers:Note that
sscanf()returns the number of successful conversions (and assignments) it made, which is why the return value must be checked before relying on the values of the output variables.