是一个与链表相关的代码,输入学生总人数及,每个学生的姓名成绩,并将输入的内容显示出来。。
VC6.0能编译通过,VS2013报错error C4703: 使用了可能未初始化的本地指针变量“p1”
代码如下:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
typedef struct student
{
char name[15];
int mark;
struct student *next;
}Node,*node;
main()
{
int num,i;
node p,p1,head;
head=(node)malloc(sizeof(Node)); /*分配内存地址*/
if(head==NULL) /*判断地址分配是否成功*/
{
printf("error");
exit(1);
}
else
head->next=NULL;
printf("please input the number of students:\n");
scanf("%d",&num);
printf("please input information:");
for(i=0;i<num;i++)
{
p=(node)malloc(sizeof(Node));
if(p==NULL)
{
printf("error");
exit(1);
}
else
{
printf("\nname:");
scanf("%s",p->name);
printf("mark:");
scanf("%d",&p->mark);
if(head->next==NULL)
{
head->next=p; /*头结点的next域指向p*/
p1=p; /*p1指向p*/
}
else
{
p1->next=p; /*将p链到链表中*/
p1=p;
}
}
}
p1->next=NULL; /*将链表中最后一个结点的指针域置空*/
p=head->next;
printf("the list:\n");
while(p!=NULL)
{
printf("name:%s",p->name);
printf(" mark:%d\n",p->mark);
p=p->next;
}
}
http://blog.tianya.cn/post-5285480-82795215-1.shtml
http://blog.tianya.cn/post-5285480-82795220-1.shtml
http://blog.tianya.cn/post-5285480-82795225-1.shtml
http://blog.tianya.cn/post-5285480-82795233-1.shtml
http://blog.tianya.cn/post-5285480-82795240-1.shtml
http://blog.tianya.cn/post-5285480-82795245-1.shtml
http://blog.tianya.cn/post-5285480-82795251-1.shtml
http://blog.tianya.cn/post-5285480-82795254-1.shtml
http://blog.tianya.cn/post-5285480-82795261-1.shtml
http://blog.tianya.cn/post-5285480-82795266-1.shtml
http://blog.tianya.cn/post-5285480-82795270-1.shtml
http://blog.tianya.cn/post-5285480-82795277-1.shtml
http://blog.tianya.cn/post-5285480-82795283-1.shtml
http://blog.tianya.cn/post-5285480-82795291-1.shtml
http://blog.tianya.cn/post-5285480-82795303-1.shtml
http://blog.tianya.cn/post-5285480-82795310-1.shtml
http://blog.tianya.cn/post-5285480-82795322-1.shtml
http://blog.tianya.cn/post-5285480-82795334-1.shtml
http://blog.tianya.cn/post-5285480-82795352-1.shtml
http://blog.tianya.cn/post-5285480-82795362-1.shtml
http://blog.tianya.cn/post-5285480-82795385-1.shtml
http://blog.tianya.cn/post-5285480-82795391-1.shtml
http://blog.tianya.cn/post-5285480-82795400-1.shtml
http://blog.tianya.cn/post-5285480-82795411-1.shtml
http://blog.tianya.cn/post-5285480-82795417-1.shtml
http://blog.tianya.cn/post-5285480-82795426-1.shtml
http://blog.tianya.cn/post-5285480-82795431-1.shtml
http://blog.tianya.cn/post-5285480-82795441-1.shtml
http://blog.tianya.cn/post-5285480-82795453-1.shtml
http://blog.tianya.cn/post-5285480-82795459-1.shtml
http://blog.tianya.cn/post-5285480-82795465-1.shtml
http://blog.tianya.cn/post-5285480-82795471-1.shtml
http://blog.tianya.cn/post-5285480-82795478-1.shtml
http://blog.tianya.cn/post-5285480-82795482-1.shtml
http://blog.tianya.cn/post-5285480-82795487-1.shtml
http://blog.tianya.cn/post-5285480-82795495-1.shtml
http://blog.tianya.cn/post-5285480-82795506-1.shtml
http://blog.tianya.cn/post-5285480-82795518-1.shtml
http://blog.tianya.cn/post-5285480-82795525-1.shtml
http://blog.tianya.cn/post-5285480-82795538-1.shtml
http://blog.tianya.cn/post-5285480-82795548-1.shtml