It is necessary to write a program that reads a two-dimensional array from a file, the name of which is entered into the console from the keyboard, and outputting the read array to the screen. Help me find a bug

int main(int argc, char* argv[]) { int i, j; FILE *in = fopen(argv[1], "rt"); if ((in) == NULL) { printf("Cannot open file.\n"); } for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { fscanf(in, "%d", &A[i][j]); printf("%d ", A[i][j]); } printf("\n"); } getchar(); return(0); } 

PS Issue resolved

  • @Andrey Gabrielyan, please: - firstly, in the question, be sure to write what exactly the error is (compiler messages, the program crashes, I expected one result, but I see another and bring the text you see (well, we're programmers, not magicians telepaths)); - secondly, do not change the erroneous text of the program to the correct one in the text of the question (this is very confusing), add corrections in the new text at the end of the question; - thirdly, in the question text (in the code) also give all the variable definitions related to this code (for example, you do not describe the array A[][] in the question). - avp

1 answer 1

 ... int main(int argc, char** argv) { int i, j; FILE *in = fopen(argv[1], "rt"); ... 

That's the way it should be. char** argv instead of char* argv and fopen(argv[1], "rt") instead of fopen(&argv[1], "rt")

  • Fortunately, I solved the problem myself. After argv you need to put [] and in fopen remove & in front of him and everything will be in chocolate. But thanks anyway =). The question is closed. - Andrei Gabrielyan
  • Actually, that's what I wrote. - iksuy