41 main(
int argc,
char *argv[])
47 fprintf(stderr,
"specify an input file\n");
53 ifp = fopen(argv[1],
"r");
54 while (fgets(line,
sizeof(line), ifp) != NULL) {
55 char *count_s, *point_s;
57 int len = (int)strlen(line);
60 if (cp[len-1] ==
'\n') {
65 cp = strchr(line,
' ');
69 cp = strchr(line,
'/');
73 sum_count += atoi(count_s);
74 sum_point += atoi(point_s);
78 double pi = 4.0 * sum_count / sum_point;
83 ofp = fopen(
"pi.out",
"w");
84 fprintf(ofp,
"%f\n", pi);
int main(int argc, char *argv[])
Main function.
#define LINELEN
Maximum length of a line of data.