C语言 语法定义错误 在void insert_Linklist(Linklist H,char x[],y[]),哪里错啊??

来源:百度知道 编辑:UC知道 时间:2024/06/23 08:55:21
#include "stdio.h"
#define Null 0
typedef struct node
{
char str[4];
struct node *next;
}Lnode,*Linklist;

/*函数*/

Linklist creat_Linklist(char A[],int n)
{ Linklist H=Null;
Lnode *p,*r=Null;
int i;
for(i=0;i<n+1;i++)
{
p=(Lnode*)malloc(sizeof(Lnode));
strcpy(p->str,A[i]);
if(H==Null)
{
H=p;
r=p;
}
else
{
r->next=p;
r=r->next;
}
}
r->next=Null;
return H;
}

void insert_Linklist(Linklist H,char x[],y[])
{
Lnode *q=H->next;
Lnode *t,*s=H;
t=(Lnode*)mallco(sizeof(Lnode));
strcpy(t->str,x);

while(q!=Null && strcmp(q->str,y)!=0)
{
s=q;
q=q->next;
}

if(strcmp(q->str,y)==0)
{
s->next=t;t->next=q;
}
else
pr

有对于A[1][4]={"Apr"};等的赋值这几行 它说表达语法错误。
肯定有错啊,矩阵字符型数组,你赋值为字符串,"Apr"这些都是字符串,‘A’这种类型的字符就可以,

scanf("%d\n",&g);它说我没定义g……无语死了……明明前面有int g

对于这个,,c语言的所有定义都要预先定义好,不能即用即定义,这和c++有区别,,c++中就可以要用的时候才定义都可以,但是c语言就不行,就是说,int g 要放在所有执行语句之前,这里应该放在第一行或者第二行。

p=H->next这句话没错,但是p这些要定义在执行语句之前,你这样放这里是没法被识别的,

还有,写程序有个忌讳,就是在main函数里面不要放一些if啊,switch的东西太多了,
第一:杂乱无章;
第二:不利于调试;
第三:就像这样错了,也不知道错在哪里;
等等。。