// 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 joe[3]; joe[0] = 1; joe[1] = 27; joe[2] = 9; fwrite(joe, 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)); fprintf(stdout, "number of items read = %d\n", fread(joe, sizeof(float), 3, fp_r)); fprintf(stdout, "file position = %d\n", ftell(fp_r)); fclose(fp_r); for (long i = 0; i < 3; i++) { fprintf(stdout, "%d: %f\n", i, joe[i]); } // exit gracefully // return 0; }