initial import
[staff/goc4/2018bti7061.git] / c-5-structuresFiles / examples / c-files / writeBinary.c
1 #include <stdio.h>
2
3 int main(){
4 FILE *file_pointer;
5 file_pointer = fopen("output.bin","w");
6 puts("Type a number");
7 int nb;
8 scanf(" %d",&nb);
9
10 int data[nb];
11 int data_size = nb;
12 int i;
13 for(i=0;i<data_size;i++){
14 data[i]=i*2;
15 }
16 char* data_char = (char*)data;
17 for(i=0;i<sizeof(data);i++){
18 putc(data_char[i],file_pointer);
19 printf(" %d",i);
20 }
21
22 fclose(file_pointer);
23 }