S
Sheldon
Hi,
I have a program here that I am trying to take to another level. That
is to say that I call a function from main, pass an array pointer,
populate the array, and then write it to a file, read it again and the
print it. The problem is that i can't get past certain errors in
compiling. I am using several online tutorials that only give simple
examples.
#define row 15
#define col 15
double readfile(double, int,int, double); 2nd error !!!
int main() {
FILE *fp;
char FILENAME[50] = "test_array.dat";
double tmp[row][col];
double *arp = &tmp[0][0]; /* pointer */
int i, j;
double count;
double array = readfile(*arp, row, col, count);
fp = fopen(FILENAME, "wb")
fwrite(tmp, sizeof count, row*col, fp)
fclose(fp);
fp = fopen(FILENAME, "rb")
fread(tmp, sizeof count, row*col, fp)
fclose(fp);
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
printf("tmp[%d,%d] = %f\n", i,j, tmp[j]);}}
return 0;}
double readfile(double *arp,int row,int col, double count){ First
error line!
int i, j;
double count;
double *arp;
count = 0.0;
for(i = 0; i < row; i++) {
for(j = 0; j < col; j++){
*arp[j] = count; 3rd error!
count++; } }
return EXIT_SUCCESS;}
The errors in compilation are:
test_readfile.c: error: parse error before numeric constant
test_readfile.c: In function `readfile':
test_readfile.c: error: number of arguments doesn't match prototype
test_readfile.c: error: prototype declaration
test_readfile.c: error: subscripted value is neither array nor pointer
I compressed the code to make it compact to publish.
Any help is greatly appreciated.
Sheldon
I have a program here that I am trying to take to another level. That
is to say that I call a function from main, pass an array pointer,
populate the array, and then write it to a file, read it again and the
print it. The problem is that i can't get past certain errors in
compiling. I am using several online tutorials that only give simple
examples.
#define row 15
#define col 15
double readfile(double, int,int, double); 2nd error !!!
int main() {
FILE *fp;
char FILENAME[50] = "test_array.dat";
double tmp[row][col];
double *arp = &tmp[0][0]; /* pointer */
int i, j;
double count;
double array = readfile(*arp, row, col, count);
fp = fopen(FILENAME, "wb")
fwrite(tmp, sizeof count, row*col, fp)
fclose(fp);
fp = fopen(FILENAME, "rb")
fread(tmp, sizeof count, row*col, fp)
fclose(fp);
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
printf("tmp[%d,%d] = %f\n", i,j, tmp[j]);}}
return 0;}
double readfile(double *arp,int row,int col, double count){ First
error line!
int i, j;
double count;
double *arp;
count = 0.0;
for(i = 0; i < row; i++) {
for(j = 0; j < col; j++){
*arp[j] = count; 3rd error!
count++; } }
return EXIT_SUCCESS;}
The errors in compilation are:
test_readfile.c: error: parse error before numeric constant
test_readfile.c: In function `readfile':
test_readfile.c: error: number of arguments doesn't match prototype
test_readfile.c: error: prototype declaration
test_readfile.c: error: subscripted value is neither array nor pointer
I compressed the code to make it compact to publish.
Any help is greatly appreciated.
Sheldon