gpt4 book ai didi

c - 增加意外错误

转载 作者:行者123 更新时间:2023-11-30 18:12:43 25 4
gpt4 key购买 nike

我正在尝试编译这段很长的代码,但是遇到了很多我不明白的错误,这是代码:(我知道它的代码很长并且有很多错误,但我发现很难解决它,尝试过所有日子都没有成功)

    #include<stdio.h>
#include<stdlib.h>

struct Data
{
int i,j,n;

}typedef Data_t;

struct Next
{
Data_t d;
Next_t* next;
}typedef Next_t;

void printMatrix(int** m,int r,int c)
{
int i,j;
printf("Matrix created is:\n");
for (i=0 ; i<r ; i++)
{
for( j=0 ; j<c ; j++)
{
printf("%d\t",m[(i*r)+j]);
}
printf("\n");
}
}

int calcMatrix(int** m,int r,int c,Next_t** d,Data_t** arr)
{
int i,j,counter=0;
printf("Enter values to the Matrix: \n");
for (i=0; i<r ; i++)
{
printf("Enter values to row #%d: ",i+1);
for(j=0; j<c ; j++)
{
scanf("%d",&m[(i*r)+j]);
}
}

printMatrix(m,r,c);
Next_t* temp1,*temp2;

for (i=0; i<r ; i++)
{
for (j=0 ; j<c ; j++)
{
if (m[i][j] == i+j)
{
counter++;
temp1 = (Next_t*)malloc(sizeof(Next_t));
temp1->d.n = m[i][j];
temp1->d.i = i;
temp1->d.j = j;
temp1->next = NULL;

if (*d == NULL) //add new triplet to the list
*d = temp1;
else
{
temp2 = *d;
while (temp2->next != NULL)
temp2 = temp2->next;
temp2->next = temp1;
}
}
}
}
if (counter!=0)
{
*arr = (Data_t*)malloc(counter*sizeof(Data_t));
temp2 = *d;
for (i = 0; i < counter;i++)
{
(*arr)[i] = temp2->d;
temp2 = temp2->next;
}
}
return counter;
}


void main()
{
int r,c,**m,solution;
int i;
Next_t** d;
Data_t** arr;
printf("Please enter number of rows for Matrix: ");
scanf("%d",&r);
printf("Please enter number of cols for Matrix: ");
scanf("%d",&c);
m = (int**)malloc(r*(sizeof(int*)));
for (i=0 ; i<c ; i++)
{
m[i] = (int*)malloc(c*(sizeof(int)));
}
solution = calcMatrix(m,r,c,d,arr);
printf("Size of Array Is: %d",solution);


}

我收到如下错误:

matala0103.c(13): error C2061: syntax error : identifier 'Next_t'
matala0103.c(14): error C2059: syntax error : '}'
matala0103.c(30): error C2143: syntax error : missing ')' before '*'
matala0103.c(30): error C2081: 'Next_t' : name in formal parameter list illegal
matala0103.c(30): error C2143: syntax error : missing '{' before '*'
matala0103.c(30): error C2371: 'Data_t' : redefinition; different basic types
matala0103.c(8) : see declaration of 'Data_t'
matala0103.c(30): error C2143: syntax error : missing ';' before '*'
matala0103.c(30): error C2059: syntax error : ')'
matala0103.c(31): error C2054: expected '(' to follow 'arr'
\matala0103.c(89): error C2065: 'Next_t' : undeclared identifier
matala0103.c(89): error C2297: '*' : illegal, right operand has type 'int *'
matala0103.c(90): error C2275: 'Data_t' : illegal use of this type as an expression
matala0103.c(8) : see declaration of 'Data_t'

非常感谢任何可以帮助我的人!伊泰。

最佳答案

查看输出的第一个警告或错误通常很有帮助,因为后来的错误通常是由第一个错误引发的多米诺骨牌问题造成的。在这种情况下,第一个错误是

matala0103.c(13): error C2061: syntax error : identifier 'Next_t'

意味着编译器无法弄清楚 Next_t 的含义。这是因为您在实际定义它之前引用了它;此时,编译器不知道 Next_t 是什么。如果将类型更改为编译器已经看到的类型,例如 struct Next_t* next; ,它会工作得更好。

关于c - 增加意外错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32288126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com