Bonjour à tous!!
Je voudrais récupérer des infos dans un fichier texte qui ressemble à ça
En fait je veux récuperer les infos des lignes commencants par CAL2, et je dois tester aussi si ma variable appellée g2header.Stn correspond bien à BARC, situé après le CAL2.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 CAL2 BARC HHE NANO STS2 2.12206591e-02 0.200 100.00000 2005/02/02 00:00 2037/01/01 00:00 PAZ2 01 V 1.50000000e-06 1 2 -5.20000000e-02 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 DIG2 02 1.00000000e+06 100.00000 CAL2 BARC HHN NANO STS2 2.12206591e-02 0.200 100.00000 2005/02/02 00:00 2037/01/01 00:00 PAZ2 01 V 1.50000000e-06 1 2 -5.20000000e-02 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 DIG2 02 1.00000000e+06 100.00000 CAL2 BARC HHZ NANO STS2 2.12206591e-02 0.200 100.00000 2005/02/02 00:00 2037/01/01 00:00 PAZ2 01 V 1.50000000e-06 1 2 -5.20000000e-02 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 DIG2 02 1.00000000e+06 100.00000
J'ai commencé à écrire qqch mais je dois dire que je reste un peu bloqué:
Merci d'avance pour votre aide!!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 fpp = fopen(calib_file,"r"); fgets(line,256,fpp); while ( feof(fpp) == 0 ) { if ( line[0] != '#' ) { if ( strlen(line) > 2 ) { if ( strncmp(line,"CAL2 ",5) == 0 ) { scanf(line,"%*s %s %s %s %s %d %d",&station_name,&station_chan,&station_aux,&station_sensor,&calib,&calper); if ( strcmp(station_name,g2head.Stn)==0){ if ( strcmp(station_chan[2],g2head.Chn[2])==0){ strcpy(g2head->Chn,station_chan); strcpy(g2head->Aux,station_aux); g2head->CalibFact=calib; g2head->CalibPer=calper; strcpy(g2head->SensorType,station_sensor); if ( strcmp(station_chan,"HHE")==0 ){ g2head.Hang=90.0; g2head.Vang=90.0; } if ( strcmp(station_chan,"HHN")==0 ){ g2head.Hang=90.0; g2head.Vang=0.0; } if ( strcmp(station_chan,"HHZ")==0 ){ g2head.Hang=-1.0; g2head.Vang=-1.0; } } } } } } fgets(line,256,fpp); } fclose(fpp);
peuf23
Partager