If I have a string str:
char str[100] = "\"Chan Tai Man\",\"E\",5000";
That is, when cout << str;
the following will appear: "Chan Tai Man","E",5000"
Now I want to extract the different FIELD of the string into different "substrings", str1, str2, int1
I wish str1 would hold the three words withOUT the quotes "Chan Tai Man".
And that str2 hold the single letter E.
And int1 would hold the integer value of 5000.
How can I do so?
I have used normal <string.h> technique with loops but in vain.
And I have used scanf technique:
char str1[50], str2[50], str3[50];
char str[100] = "\"Chan Tai Man\",\"E\",5000";
// read fields using scanset
sscanf(str, "%s%s%i", str1, str2, str3);
cout << "str1 = " << str1 << ", str2 = " << str2 << ", str3 = " << str3 << endl;
But scanf always stop reading when it meets the space characters. It make str = "Chan which I dont want. And the str is of string type but I wanted integer type.
So many problems, Anyone can help???
Thanks~