Hi im currently reading "teach yourself C in 21 days" from SAMS. I'm at chapter 14 "working with the screen, printer and keybord).
Well i decided to do some testing with sscanf. I have this file with this contents:
Code:A807091452|11571719|+2.168403E-07|T|P A807091454|11571719|+2.170490E-07|T|P A807091454|11550661|+2.113044E-07|T|P
This is the code:
In my opinion the fisrt "A" is read bij %*c, the next string "807091454" bij %[1234567890] the "|" by %*c, then "11571719" by %[1234567890] "|+" by %*2c and then the float "2.168403".Code:int get_mean(FILE *fp) { int i = 0; char date[MAX+1], serial[MAX+1], measure[MAX+1], buff[MAX+1]; float mes; while( (fgets(buff, 100, fp)) != NULL) { sscanf(buff, "%*c %[1234567890] %*c %[1234567890] %*2c %2.2f ", date, serial, &mes); printf("%s %s %f\n", date, serial, mes); } return 0; }
But is does not do what i expect i to do...
when i run the program this comes out:
Can somebody give me a clue ?Code:807091452 11571719 0.000000 807091454 11571719 0.000000 807091454 11550661 0.000000



LinkBack URL
About LinkBacks



. 