O....I think it might be due to the pointer problems....
ok here's the new version of the functions, actually they're about the same
the writing function is like this
void Send_field1(filename, field)
char *filename;
FIELD2N *field;
{
INDEX i;
FILE *fptr;
if ((fptr = fopen(filename, "a")) == NULL)
printf("Error opening file\n");
printf("before printing\n");
SUMLOOP(i) fprintf(fptr, "%04x ", field->e[i]);
if (fclose(fptr) == EOF)
printf("Error closing file\n");
}
- void Send_field1(filename, field)
- char *filename;
- FIELD2N *field;
- {
- INDEX i;
- FILE *fptr;
- if ((fptr = fopen(filename, "a")) == NULL)
- printf("Error opening file\n");
- printf("before printing\n");
- SUMLOOP(i) fprintf(fptr, "%04x ", field->e[i]);
- if (fclose(fptr) == EOF)
- printf("Error closing file\n");
- }
and the reading part is like this
void Receive_field1(filename, field)
char *filename;
FIELD2N *field;
{
INDEX i;
FILE *fptr;
if ((fptr = fopen(filename, "r")) == NULL)
printf("Error opening file\n");
printf("before reading\n");
SUMLOOP(i) {fscanf(fptr, "%x ", &field->e[i]); printf("field->e[i] %04x\n", field->e[i]);}
if (fclose(fptr) == EOF)
printf("Error closing file\n");
}
- void Receive_field1(filename, field)
- char *filename;
- FIELD2N *field;
- {
- INDEX i;
- FILE *fptr;
- if ((fptr = fopen(filename, "r")) == NULL)
- printf("Error opening file\n");
- printf("before reading\n");
- SUMLOOP(i) {fscanf(fptr, "%x ", &field->e[i]); printf("field->e[i] %04x\n", field->e[i]);}
- if (fclose(fptr) == EOF)
- printf("Error closing file\n");
- }
I wrote sth into the file and the wriing part is perfectly ok as before
I wrote
685 43c6fffc e02152ec 87fd5959
yes a bit messy, it's a random hexadecimal
But when I tried to see what the readinf function read from the file...I got this
so it is still not reading the right thing
And here's some of the declarations I made beforehand
typedef struct {
ELEMENT e[MAXLONG];
} FIELD2N;
- typedef struct {
- ELEMENT e[MAXLONG];
- } FIELD2N;
where MAXLONG = 4
and that SUMLOOP is defined as
#define SUMLOOP(i) for(i=0; i<MAXLONG; i++)
simply a way to define the loop which will be frequenylt used in the program
So anyone got any idea about where it went wrong?
Thanz!!
