Is there a way to force sscanf to NOT allow extra whitespace.
Following code accepts "N_ 234", even though it should only accept "N_234":
int r;
unsigned b;
r = sscanf("N_ 234", "N_%u", &b); /* Returns 1 */
Tested with IAR compiler.
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.
May be my code helpful to you:
printf("%u\n",b);output correct value if there no space andris 1, otherwiseb= 0 andris -1 (EOF).Give it a try!!
EDIT: There is chance of e buffer overrun but can be corrected using dynamic allocation.