/* * Program to write integers to binary file. * * (To look at the file, you can use "od -t x1 filename" to print it one * byte at a time in hexadecimal.) */ #include #include /* main program */ int main(int argc, char *argv[]) { if (argc != 2) { printf("usage: %s outfile\n", argv[0]); return 1; } FILE * outfile = fopen(argv[1], "wb"); if (outfile == NULL) { printf("cannot open output file %s\n", argv[1]); return 1; } for (int i = 1; i <= 10; ++i) { fwrite(&i, sizeof(i), 1, outfile); } fclose(outfile); return 0; }