27 #include <sys/types.h> 40 main(
int argc,
char *argv[])
46 srand((
unsigned int)getpid());
49 fprintf(stderr,
"specify an input file\n");
53 ifp = fopen(argv[1],
"r");
54 if (fgets(line,
sizeof(line), ifp) == NULL) {
55 fprintf(stderr,
"failed to read the input file\n");
62 for (i = 0; i < points; i++) {
63 float x = (float)rand() / ((float)RAND_MAX + 1.0F);
64 float y = (float)rand() / ((float)RAND_MAX + 1.0F);
65 if ( x * x + y * y < 1.0) {
70 char *ofilename = malloc(strlen(argv[1]) + 5);
71 strncpy(ofilename, argv[1], strlen(argv[1]) + 1);
72 strncat(ofilename,
".out", 4);
74 ofp = fopen(ofilename,
"w");
75 fprintf(ofp,
"%d/%d\n", count, points);
int main(int argc, char *argv[])
Main function.
#define LINELEN
Maximum length of a line of data.