求大神帮忙,该程序是我代码的一部分,我执行后,输入第一个字符串时,老报内存错。
程序代码:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 40
struct Tcb
{
char name [MAX];
char sex [MAX];
struct Tcb * next;
};
int main()
{
struct Tcb *head = NULL;
struct Tcb *prev,*current;
char input[MAX];
printf("Input the first name:");
while(gets(input) != NULL&&input[0] != '\0')
{
current = (struct Tcb *)malloc(sizeof(struct Tcb));
if(head = NULL)
head = current;
else
prev->next = current;
current->next = NULL;
strcpy(current->name,input);
puts("Input the sex:");
gets(current->sex);
puts("Enter the next name:");
prev = current;
}
return 0;
}








