S
Simon
I'm trying to write a little function to save data. Basically I have a
large 2d array of structs, so I'm going to have to call the save
function once per struct in the array. I'd like to save the data using
fwrite(). After quite a lot of effort I've come up with the code
below, but I'm having real difficulty getting rid of the last error.
When compiling, I get this:
Line 52: "warning: assignment makes pointer from integer without a
cast"
I'm not sure what's causing this but it's very confusing. Can anyone
help?
Simon
--Code below--
#include <stdio.h>
struct test
{
char char1;
char char2;
char char3;
char char4;
int* pointer1;
int* pointer2;
};
main()
{
struct test test_st[3][3];
int i, j;
for (j = 0; j < 3; j++)
{
for (i = 0; i < 3; i++)
{
test_st[j].char1 = 1;
test_st[j].char2 = 1;
test_st[j].char3 = 1;
test_st[j].char4 = i;
test_st[j].pointer1 = NULL;
test_st[j].pointer2 = NULL;
}
}
FILE *fp = fopen ("test.csd_saved_game", "w");
struct test *p;
p = &test_st[j];
write_struct (fp, p);
/* p -> char1;
fwrite (p, 1, 1, fp);
fread (test_char, */
return 0;
}
write_byte (FILE *fp, unsigned char *temp, int bytes)
{
fwrite (temp, 1, bytes, fp);
}
write_struct (FILE *fp, struct test *p)
{
unsigned char *temp;
temp = p -> char1; <<<<ERROR IS HERE
write_byte (fp, temp, sizeof(char));
}
large 2d array of structs, so I'm going to have to call the save
function once per struct in the array. I'd like to save the data using
fwrite(). After quite a lot of effort I've come up with the code
below, but I'm having real difficulty getting rid of the last error.
When compiling, I get this:
Line 52: "warning: assignment makes pointer from integer without a
cast"
I'm not sure what's causing this but it's very confusing. Can anyone
help?
Simon
--Code below--
#include <stdio.h>
struct test
{
char char1;
char char2;
char char3;
char char4;
int* pointer1;
int* pointer2;
};
main()
{
struct test test_st[3][3];
int i, j;
for (j = 0; j < 3; j++)
{
for (i = 0; i < 3; i++)
{
test_st[j].char1 = 1;
test_st[j].char2 = 1;
test_st[j].char3 = 1;
test_st[j].char4 = i;
test_st[j].pointer1 = NULL;
test_st[j].pointer2 = NULL;
}
}
FILE *fp = fopen ("test.csd_saved_game", "w");
struct test *p;
p = &test_st[j];
write_struct (fp, p);
/* p -> char1;
fwrite (p, 1, 1, fp);
fread (test_char, */
return 0;
}
write_byte (FILE *fp, unsigned char *temp, int bytes)
{
fwrite (temp, 1, bytes, fp);
}
write_struct (FILE *fp, struct test *p)
{
unsigned char *temp;
temp = p -> char1; <<<<ERROR IS HERE
write_byte (fp, temp, sizeof(char));
}