I have a problem with my code and I hope you can help. I won't post all the code because it's a little long, but I will focus on the troublesome part. The program is about algebraic operation with arrays. The read_array2 reads the first nxn real numbers from a file and place them in a global array. The problem is that I always get the same message "I cannot open this file". I even added a printf() to test if the name is properly stored in fname and I found that it is. And yes, I have verified that the files I use exist and I type their names correctly. I don't know if it is important, but the files have 10000 real numbers separated by a single space. I know it is difficult to tell without all the code available, but do you see something out of place that could cause this issue?
int read_array2(double table[N_MAX][N_MAX], int n){
int i, j;
FILE *infile;
char fname[25];
printf("\nFile Name: ");
scanf("%s",&fname);
if ((infile = fopen(fname,"r")) == NULL){
printf("\nI cannot open this file.\n");
return 1;
}
for (i = 0; i < n; i++)
for(j = 0; j < n; j++){
fscanf(infile, "%lf ", &table[i][j]);
}
fclose(infile);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire