
每次運行到這會出現這樣的CPU錯誤,不知道是哪里的邏輯錯了還是語法錯了

下面是代碼:
#include<stdio.h>
#include<malloc.h>
struct link{
char name;
int Long;
struct link *next;
};
struct tu{
char name[25];
int Long;
struct link *head[25];
};
int main()
{
int n,m,i,I;
scanf("%d %d",&n,&m);
struct tu *map=(struct tu *)malloc(sizeof(struct tu *));
map->Long=n;
for(i=0;i<n;i++){
scanf(" %c",&map->name[i]);
map->head[i]=NULL;
}
struct link *get;
char name1,name2,Long;
for(i=0;i<m;i++){
scanf("%c %c %d",&name1,&name2,&Long);
get=(struct link *)malloc(sizeof(struct link *));
for(I=0;I<map->Long;I++){
if(map->name[I]==name2) break;
}
get->name=I;
get->Long=Long;
for(I=0;I<map->Long;I++){
if(map->name[I]==name1) break;
}
get->next=map->head[I];
map->head[I]->next=get;
}
for(i=0;i<n;i++){
printf ("%c\n",map->name[i]);
get=map->head[i]->next;
while(get){
printf (" %d %d\n",get->name,get->Long);
get=get->next;
}
}
return 0;
}
uj5u.com熱心網友回復:
申請的記憶體大小不對,把 * 去掉。struct tu *map=(struct tu *)malloc(sizeof(struct tu *));
get=(struct link *)malloc(sizeof(struct link *));
uj5u.com熱心網友回復:
scanf("%c %c %d",&name1,&name2,&Long);這里錯了,應該是%c轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/53631.html
標籤:C語言
