Program crash writing to binary file

cant write to binary file


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
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int number;
} something;
void main()
{
int numbers[10]={1,2,3,4,5,6,7,8,10,12};
int age=15;
something abc[4]={
{5},
{10},
{15},
{20}};
FILE * f;
if ((f=fopen("numbers.bin","wb"))==NULL){
printf("Error opening file");
exit(1);
}

fwrite(&numbers,sizeof(int),10,f);
fwrite(age,sizeof(int),1,f);
fwrite(&abc,sizeof(something),4,f);
fclose(f);
}
Last edited on
http://www.cplusplus.com/forum/general/112111/

bar.c:6:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
bar.c: In function ‘main’:
bar.c:22:2: warning: passing argument 1 of ‘fwrite’ makes pointer from integer without a cast [enabled by default]


int main()

fwrite(&age,sizeof(int),1,f);
Last edited on
Editing out your topic after it's solved is a jerk move, you should refrain from doing that in the future. Others may have had the same problem as you, and now they can't solve it because they can't confirm their error(s).
Topic archived. No new replies allowed.