为什么age不能正常输出,求助!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
typedef struct
{
char key[10];
char name[20];
char age;
}Data;
typedef struct Node
{
Data DataNode;
struct Node *nextNode;
}lsType;
lsType *AddNode(lsType *head,Data data)
{
lsType *NewNode,*TempNode;
if (!(NewNode =(lsType *)malloc(sizeof(lsType))))
{
printf("fai!/n");
return NULL;
}
NewNode->DataNode = data;
NewNode->nextNode = NULL;
if (head == NULL)
{
head = NewNode;
return head;
}
TempNode = head;
while (TempNode->nextNode!=NULL)
{
TempNode = TempNode->nextNode;
}
TempNode->nextNode = NewNode;
return head;
}
void showAllNode(lsType *head)
{
lsType *temp ;
temp =head;
while (temp)
{
printf("the Node is(key:%s name:%s age:%s)\n",temp->DataNode.key,temp->DataNode.name,temp->DataNode.age);
temp = temp->nextNode;
}
}
void main()
{
lsType *head = NULL;
Data nodeData;
printf("Enter the data:key,name,age\n");
do
{
fflush(stdin);
scanf("%s",nodeData.key);
if (strcmp(nodeData.key,"0") == 0)
{
break;
}
else
{
scanf("%s%d",nodeData.name,nodeData.age);
head = AddNode(head,nodeData);
}
} while(1);
showAllNode(head);
getch();
}
[解决办法]
scanf("%s%d",nodeData.name,&nodeData.age);
那个不要这样么
没编译器不知道可不可以 还有你这样贴代码 没人看的