I have a text file which has first line as below:
j0W82LBrSdUbw
Basically it can have many space,horizontal tabs in beginning then some characters having numbers or alphabets(width of this is 14 characters – fixed), and then some more space or tabs could be present. The width of the whole line is not known, i mean it could have any number of spaces or tabs in it. I want to neglect the leading and trailing white space but only take the letters/numbers into a string.
I tried to read it using fscanf with character class as shown below(I tried couple of ways but without success), but result is incorrect, it is not reading and ignoring the space , nor the actual letters are read. For test purpose I fixed the whole length of line to 54 characters in all(white spaces, numbers characters all included)
fscanf(fin,"%54*[ ]%[^ ]%*[ ]",s);//s is char array char s[100];
and
fscanf(fin,"%54[^ \t]",s);
1] How do I parse this using fscanf when width of line is fixed and known say 54 characters.
2]When width of line is unknown and variable?
3]Where can I read a good documentation about using character classes in scanf/fscanf?
Try
fgetc()in a loop. You may need to add error checking and treatment of borderline cases.