Try this
Code:
#include<stdio.h>
int main ( ) {
FILE *fp;
fp = fopen("foo.txt","r");
while ( 1 ) {
int id, result;
double val;
result = fscanf( fp, "%d:%lf", &id, &val );
if ( result == 1 ) {
printf("ID: ID=%d\n", id );
} else
if ( result == 2 ) {
printf("Pair: Value=%f\n", val );
} else {
/* almost certainly EOF, but in any case we're done */
break;
}
}
fclose(fp);
return 0;
}
$ cat foo.txt && ./a.exe
1 1:.2345 2:.3454 3:.238909 10000:.4329407
-1 1:.1201890 2:.121211 10000:.3123123
ID: ID=1
Pair: Value=0.234500
Pair: Value=0.345400
Pair: Value=0.238909
Pair: Value=0.432941
ID: ID=-1
Pair: Value=0.120189
Pair: Value=0.121211
Pair: Value=0.312312