Answer the question
In order to leave comments, you need to log in
What is the reason for these errors and how to fix it?
78 8 C:\Users\User\Desktop\1.c [Error] redefinition of 'file'
41 11 C:\Users\User\Desktop\1.c [Note] previous definition of 'file' was
here be?
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
int main(){
int l;
int m = 0, n = 0
, k = 0
, x = 0
, i = 0, j = 0, w = 0;
int** a;
l = getchar();
switch(l)
{
case 'a':
scanf("%d%d%d", &k, &n, &m);
a = (int**)malloc(n * sizeof(int*));
for (i = 0; i < n; i++)
{
a[i] = (int*)malloc(m * sizeof(int));
for (j = 0; j < m; j++) { a[i][j] = 0; }
}
for (w = 0; w < k; ++w)
{
for (i = 0; i < n; i++)
{
for (j = 0; j<m; j++)
{
printf("a[%d][%d] = ", i, j);
scanf("%d", &x);
a[i][j] += x;
}
}
}
printf("\nsumm: \n");
FILE* file = fopen("file.txt", "w");
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
fprintf(file, "%d %d ", i, j);
}
fclose(file);
}
return 0;
case 'b':
scanf("%d%d%d", &k, &n, &m);
a = (int**)malloc(n * sizeof(int*));
for (i = 0; i < n; i++)
{
a[i] = (int*)malloc(m * sizeof(int));
for (j = 0; j < m; j++) { a[i][j] = 0; }
}
for (w = 0; w < k; ++w)
{
for (i = 0; i < n; i++) //строки
{
for (j = 0; j<m; j++)
{
printf("a[%d][%d] = ", i, j);
scanf("%d", &x); //считываем значение матрицы
a[i][j] += x;
}
}
}
printf("\nsumm: \n");
FILE* file = fopen("file.txt", "w");
for (j = 0; j < n; j++) {
for (i = 0; i < m; i++) {
fprintf(file, "%d %d ", i, j);
}
fclose(file);
return 0;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question