The code on the C seems to be how much I looked through the forums, the code corrects I sin on entering dimensions from the keyboard displays a matrix filled with zeros when I added

if(fp==NULL) { puts("Open file error"); return; } 

It began to display "Open file error"

please tell me what the problem is

 printf("Введите количество строк матрицы А "); scanf("%d", &m); printf("Введите количество столбцов матрицы А "); scanf("%d", &n); float A[m][n]; FILE* fp; fp = fopen("matrixA.txt", "rt"); if (fp == NULL) { puts("Open file error"); return; } for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { fscanf(fp, "%f ", &A[i][j]); } } printf("\nМатрица А \n"); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { printf("%f\t", A[i][j]); } printf("\n"); } fclose(fp); 
  • one
    and the file is exactly? And the rule of access to it is set? - pavel
  • Errors should be output something like this: printf( "Can not open file \"%s\" : %s\n", filename, strerror(errno) ); or perror( "Can not open file" ); Without this - an underground knock, which makes no sense to discuss. - PinkTux
  • Is the file in the program directory? - VladD
  • I hesitate to ask, and what's in the second parameter in fp = fopen("matrixA.txt", "rt"); does the letter t mean? Can there not be only a , a+ , w , w+ , r , r+ ? - Max ZS

1 answer 1

The problem you have is that the matrixA.txt file does not open. Most likely, it simply does not exist in the current directory from which your program is launched.

The fact that before this message was not, does not mean that everything was good - the program simply did not complain that it was really bad ... :)

  • I do not know. Everything lies in one folder. At first everything was on the desktop, and then I also threw it into a separate folder, but this did not work. - Rrttr
  • 3
    I don't know ” is not a conversation at all. Either provide an accurate diagnosis (for example, above in the comments), or talk and nothing. - PinkTux