I have a file that contains data in this form:
1 Jake 234 Ruby 98.
I want to use sscanf to read only the strings into arrays, so I tried this:
male[i] = malloc(100);
female[i] = malloc(100);
sscanf(str, "%*d%s%*d%s%*d", &male[i], &female[i]);
The problem is that when i = 0, the function skips the first string along with the first integer. So when I try to print &male[0], I get a blank space.
I have initialised i to be 0. Could someone please point out where I might be going wrong?
Thanks a lot!
sscanf(str, "%*d%s%*d%s%*d", male[i], female[i]);printf("%s %s\n", male[i], female[i]);sscanf()? You must test the to know how much of it worked, which helps identify where the problem is. You'll never know whether the last%*dsucceeded so it may as well be deleted.