首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

为什么age不能正常输出,

2012-10-10 
为什么age不能正常输出,求助!#include stdio.h#include string.h#include stdlib.h#include conio.

为什么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);
那个不要这样么
没编译器不知道可不可以 还有你这样贴代码 没人看的

热点排行
Bad Request.