I want to parse $100,50,30# using sscanf and store 100 50 and 30 into seperate variables. How can i do it...
I want to parse $100,50,30# using sscanf and store 100 50 and 30 into seperate variables. How can i do it...
Suppose you had those three variables. Do you know how to print them in that format using printf? If so, show an example code snippet.
Suppose you had the string "123". Do you know how to use sscanf to parse it into an int variable? If so, show an example code snippet.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I can do something like this:
char *str= "$100,50,40#";
char buf1[1], buf2[1],buf3[1];
sscanf(str, "%[^','],%[^','],%s", buf1,buf2,buf3);
int i = atoi(buf1);
int j = atoi(buf2);
int k = atoi(buf3);
but the problem is sscanf can parse and ignore , and store the tokens in buf1, buf2, and buf3....but it cant remove $ and #....i need a code to remove all the delimeters from str and store it in seperate variables..that is what i want and that too using sscanf...any help would be appreciable
Instead of making use of buf1, buf2 and buf3, try reading into i, j and k directly, with the help of %d. Remember to check that sscanf returns 3 as there could be a format error in the input.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
@OP: When posting code, you should use code tags.