hey guys, I am a beginner and am having trouble loading data from an external data file and then loading it to the screen. It is supposed to be the temperatures from everyday for a year for 2 years. 1 column is 1930 the other 2000
This is my script, and I am getting a stack overflow error:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ELEM 365
void getdata(int d[], double A[][MAX_ELEM]);
void displaydata(int d[],double A[][MAX_ELEM]);
void main(){
int d[2];
double A[MAX_ELEM][MAX_ELEM];
getdata(d,A);
displaydata(d,A);
system("pause");
}
void getdata(int d[],double A[][MAX_ELEM]){
FILE *fp;
int i, j;
fp = fopen("data.txt", "r");
fscanf(fp, " %d %d", &d[0], &d[1]);
for(i = 0; i < d[0]; i=i+1)
{
for(j = 0; j < d[1]; j=j+1)
{
fscanf(fp,"%lf", &A[i][j]);
}
}
fclose(fp);
}
void displaydata(int d[],double A[][MAX_ELEM]){
int i,j;
for(i = 0; i < d[0]; i++){
for(j = 0; j < d[1]; j++){
printf("\t%lf", A[i][j]);
}
}
}
If anyone could answer why this is happening I would greatly appreciate it.
Thanks