Code:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
struct database_input {
int category_A;
int category_B;
double category_C;
int category_D;
};
int main ( ) {
char input[] = "1.1.1.1.2 = 1.2372e-05 23 4\n"; // just like fgets() returns
struct database_input foo;
char temp[6] = { 0 };
if ( sscanf( input, "%c.%c.%c.%c.%c = %lf %d %d",
temp+0, temp+1, temp+2, temp+3, temp+4,
&foo.category_C, &foo.category_B, &foo.category_D ) == 8 ) {
foo.category_A = strtol( temp, NULL, 0 );
printf( "Input=%s", input );
printf( "A=%d, B=%d, C=%g, D=%d\n",
foo.category_A, foo.category_B,
foo.category_C, foo.category_D );
}
return 0;
}
$ gcc foo.c
$ ./a.exe
Input=1.1.1.1.2 = 1.2372e-05 23 4
A=11112, B=23, C=1.2372e-05, D=4
Having done that, you can then do this
Code:
char input[BUFSIZ];
while ( fgets ( input, sizeof input, ifp ) != NULL ) {
// now do the sscanf.
// If the result isn't 8 (in this case), then report an error
}