Drugo
Junior Member level 2
- Joined
- Feb 23, 2011
- Messages
- 20
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Activity points
- 1,537
I'm using a Microchip C30 compiler on dsPIC33F family and struggling A LOT with sscanf() function. Please please please help me because my project is getting stuck for this little detail. I really hope that someone can help me, I haven't found anything on internet and I spent the last 2 days on this issue. Thanks a lot in advance
THE TASK
I have to read different types of numbers from a string (unsigned int, float, char and unsigned char).
THE ISSUES
I have problems reading numeric char and unsigned char (i.e. 8 bit numbers, not ASCII characters), but not the other ones. With problem I mean that sscanf() fails (crashes) during its execution without returning any numeric value. In particular the problems come when I try to read more than one char (or unsigned char) in a row. As a char conversion specifier I use %hhd, but I tried - at least I think - with all the possible combinations. For unsigned char I used %hhu.
In order to understand better please look at this examples with just float and char. Float are read correctly, char just in case A) with one char parameter.
A) JUST ONE CHAR HAS TO BE READ: it works correctly :grin: :lol:
B) TWO CHARS HAVE TO BE READ: it doesn't work, sscanf() does not complete its execution and doesn't provide a return value :-(
C) THREE CHARS HAVE TO BE READ: it doesn't work, sscanf() does not complete its execution and doesn't provide a return value :-x
THANKS SO MUCH FOR YOUR HELP!!!
THE TASK
I have to read different types of numbers from a string (unsigned int, float, char and unsigned char).
THE ISSUES
I have problems reading numeric char and unsigned char (i.e. 8 bit numbers, not ASCII characters), but not the other ones. With problem I mean that sscanf() fails (crashes) during its execution without returning any numeric value. In particular the problems come when I try to read more than one char (or unsigned char) in a row. As a char conversion specifier I use %hhd, but I tried - at least I think - with all the possible combinations. For unsigned char I used %hhu.
In order to understand better please look at this examples with just float and char. Float are read correctly, char just in case A) with one char parameter.
A) JUST ONE CHAR HAS TO BE READ: it works correctly :grin: :lol:
Code C - [expand] 1 2 3 4 5 6 7 8 // 99 init values just for debugging resons char string[] = "test1 12,1.525,2.789"; char theChar1 = 99; float theFloat1; float theFloat2; int retVal = 99; retVal = sscanf(&string[6],"%f,%f,%hhd",&theFloat1, &theFloat2, &theChar1);
B) TWO CHARS HAVE TO BE READ: it doesn't work, sscanf() does not complete its execution and doesn't provide a return value :-(
Code C - [expand] 1 2 3 4 5 6 7 8 9 // 99 init values just for debugging resons char string[] = "test1 12,1.525,2.789"; char theChar1 = 99; char theChar2 = 99; float theFloat1; float theFloat2; int retVal = 99; retVal = sscanf(&string[6],"%f,%f,%hhd,%hhd",&theFloat1, &theFloat2, &theChar1, &theChar2);
C) THREE CHARS HAVE TO BE READ: it doesn't work, sscanf() does not complete its execution and doesn't provide a return value :-x
Code C - [expand] 1 2 3 4 5 6 7 8 9 // 99 init values just for debugging resons char string[] = "test1 12,1.525,2.789"; char theChar1 = 99; char theChar2 = 99; float theFloat1; float theFloat2; int retVal = 99; retVal = sscanf(&string[6],"%f,%f,%hhd,%hhd,%hhd",&theFloat1, &theFloat2, &theChar1, &theChar2, &theChar3);
THANKS SO MUCH FOR YOUR HELP!!!
Last edited by a moderator: