// file: my first program // #include //#include //#include // my main program starts here // int main(int argc, char** argv) { // declare local variables // float sum = 27.272727272; // open a file // FILE* fp = fopen(argv[1], "w"); if (fp == (FILE*)NULL) { fprintf(stdout, "%s: error opening file\n", argv[0]); } // print to the terminal as ASCII // // fprintf(fp, "%10.4f\n", sum); // print to the file as binary // float a[] = {1, 2, 3}; fwrite(a, sizeof(float), 3, fp); // close the file // fclose(fp); FILE* fp_r = fopen(argv[1], "r"); float joe[3]; fprintf(stdout, "file position = %d\n", ftell(fp_r)); long nitems_read = fread(joe, sizeof(float), 3, fp_r); nitems_read = fread(joe, sizeof(float), 3, fp_r); fprintf(stdout, "file position = %d(%d)\n", ftell(fp_r), nitems_read); // fprintf(stdout, "number of items read = %d\n", // fread(joe, sizeof(float), 3, fp_r)); fclose(fp_r); for (long i = 0; i < 3; i++) { fprintf(stdout, "%d: %f\n", i, joe[i]); } // exit gracefully // return 0; }