#include #define MAXVALUE 16 int main() { int numVals; int i, val; FILE *outfile = fopen("randomNums.txt", "w"); //use "r" to read from the file srand(time(0)); // randomize (re-seed) the "random" number generator printf("Write how many random values to the file? "); scanf("%d", &numVals); // "&" means "address-of" the variable // i.e. scanf reads a value into the address of // the variable numVals fprintf(outfile, "%d\n", numVals); for(i = 0; i < numVals; i++) { val = rand() % 16; // "random" numbers from 0..15 fprintf(outfile, "%4d", val); if (i % 10 == 9) fprintf(outfile, "\n"); // newline after each group of 10 values } fprintf(outfile, "\n"); fclose(outfile); return 0; } /* gcc -o randomNumFile randomNumFile.c ./randomNumFile Write how many random values to the file? 50 more randomNums.txt 50 9 10 10 13 2 2 14 9 8 11 10 9 0 6 14 15 13 13 2 4 10 13 8 10 12 2 3 1 3 11 2 12 5 13 9 8 15 8 1 7 3 12 0 3 2 15 2 15 12 5 */