forked from einar52/ray
-
Notifications
You must be signed in to change notification settings - Fork 1
/
readdata.c
46 lines (44 loc) · 864 Bytes
/
readdata.c
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
40
41
42
43
44
45
46
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#define SIZE 510
char buffer[SIZE] ;
char *fields[SIZE] ;
int readData( FILE *fd, char **fields)
/* Read line from fd and put a list of non-blank fields into array fields.
Returns number of fields found
*/
{
int n,nn,i,type,otype ;
char *cp ;
nn = SIZE ;
cp = fgets(buffer,SIZE,fd) ;
if( cp == NULL ) {
fclose(fd) ;
return 0 ;
}
otype = isspace(' ') ;
i = 0 ;
while( *cp ) {
type = isspace(*cp) ;
if( type && (otype ==0) ) *cp = 0 ;
if(( type == 0) && otype) { fields[i++] = cp ; }
otype = type ;
cp++ ;
}
return i ;
}
#ifdef TEST
int main()
{
FILE *ff ;
int n ;
char *fields[200] ;
double lat ;
ff = fopen("../geysir/phase.dat","r") ;
n = readData(ff,(char **) &fields) ;
lat = atof(fields[7]) ;
printf("n=%d lat=%lf _%s_\n",n,lat,fields[7]) ;
return 0 ;
}
#endif