1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage : wrinte_int file N...");
exit(1);
}
FILE * fp = fopen(argv[1], "w");
int *buf = calloc(sizeof(int), argc-2);
for (int i = 2; i < argc; ++i) {
int nb = atoi(argv[i]);
buf[i-2] = atoi(argv[i]);
}
if (argc-2 != fwrite(buf, sizeof(int), argc-2, fp)) {
fprintf(stderr, "Cannot write into given file");
}
fclose(fp);
return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
gcc -std=c99 -O2 -Wall -pedantic -xc main.cpp && ./a.out file.txt 1 2 3 4 && od -Ax -t x1 file.txt
main.cpp: In function 'main':
main.cpp:17:13: warning: unused variable 'nb' [-Wunused-variable]
   17 |         int nb = atoi(argv[i]);
      |             ^~
000000 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
000010