一个结构体的程序,出现错误,请帮忙排查
想了很久没发现错在哪里,调用字串在功能函数里可以,一切正常,但返回到main里则提示错误,请帮忙找错,谢谢程序代码:
#include <stdio.h> #include <stdlib.h> typedef struct sdu { char name[24]; char NO[24]; int chengJi; struct sdu * next; } SDU; typedef SDU * PrtSDU; void start(PrtSDU head); int main(int argc, char **argv) { PrtSDU head = NULL; start(head); printf("test head p = %p\n",&head); printf("%s\n",head->name); //这里为错误点,我错在哪里呢? printf("%s\n",head->NO); printf("%d\n",head->chengJi); printf("all ok\n"); return 0; } void start(PrtSDU head){ head = (PrtSDU)malloc(sizeof(SDU)); if (head != NULL){ scanf("%s%s%d",head->name,head->NO,&head->chengJi); printf("test start ok , %s %s %d .\n",head->name,head->NO,head->chengJi); head->next = NULL; }else{ printf("error\n"); } }