1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <stdio.h>
int main()
{
int n, N_mat, N_pnt, N_soa, N_hoa, N_bar;
bool gda = false;
bool endfile = false;
char txt[128];
char rts;
// Read input file
FILE *file = fopen("Testfile.txt", "rt");
do {
// Read line
fgets(txt, 128, file);
// If general data command is found
if( txt[0]=='G' && txt[1]=='E' && txt[2]=='N' && txt[3]=='R' )
{ n = sscanf(txt, "%s %d %d %d %d %d\n", &rts, &N_mat, &N_pnt, &N_soa, &N_hoa, &N_bar);
gda = true;
}
// If end command is found
if( txt[0]=='E' && txt[1]=='N' && txt[2]=='D' )
endfile = true;
}
while( !gda || !endfile );
// Missing commands
if( !gda )
printf(" !!! Error: cannot find the command GENR\n");
if( !endfile )
printf(" !!! Error: cannot find the command END\n");
fclose(file);
return 0;
}
| |