#include #include int main(int argc, char *argv[]) { FILE *fp; // file pointer int n; int m; if (argc != 3) { // incorrect command line argument printf("ERROR! the correct format is:\ngen \n"); return 0; } sscanf(argv[2], "%d", &n); // reads a number from string argv[2] fp = fopen(argv[1], "w"); // Open the file for writing if (fp == NULL) { // problems in opening file printf("ERROR! Cannot open the file %s\n", argv[1]); return 0; } fprintf(fp, "%d\n", n); for (int i = 0; i < n; i++) { m = rand(); // a random number in the range [0, RAND_MAX] fprintf(fp, "%d ", m); } fclose(fp); // Close the file }