C语言中怎样将字符串传递给字符型变量?
这是与结构体和链表有关的#include<stdio.h>#include<stdlib.h>#defineSTUstructstudent#defineSTNstruc...
这是与结构体和链表有关的
#include<stdio.h>
#include<stdlib.h>
#define STU struct student
#define STN struct stunode
STU
{
int num;
char name[13];
int grade;
};
STN
{
int num;
char name[13];
int grade;
STN *next;
};
main()
{
STU a[13]={{2,"Lin",92},{3,"Zhang",87},{4,"Zhao",72},{5,"Ma",91},{9,"Zhen",85},{11,"Wang",100},{12,"Li",86},
{13,"Xu",83},{16,"Mao",78},{17,"Hao",95},{20,"Lu",82},{21,"Song",76},{22,"Wu",88}};
STN *head,*p,*q;
int i;
head=NULL;
q=NULL;
for(i=0;i<13;i++)
{
p=(STN *)malloc(sizeof(STN));
p->num=a[i].num;
p->name=a[i].name;
p->grade=a[i].grade;
p->next=NULL;
if(head==NULL)
head=p;
else q->next=p;
q=p;
}
printf("学号(num)姓名(name)成绩(grade)\n");
p=head;
while(p!=NULL)
{
printf(" %-.2d %-7s %5d\n",p->num,p->name,p->grade);
q=p;
p=p->next;
free(q);
}
printf("\n");
}后边不知道怎样将名字那一块儿弄。 展开
#include<stdio.h>
#include<stdlib.h>
#define STU struct student
#define STN struct stunode
STU
{
int num;
char name[13];
int grade;
};
STN
{
int num;
char name[13];
int grade;
STN *next;
};
main()
{
STU a[13]={{2,"Lin",92},{3,"Zhang",87},{4,"Zhao",72},{5,"Ma",91},{9,"Zhen",85},{11,"Wang",100},{12,"Li",86},
{13,"Xu",83},{16,"Mao",78},{17,"Hao",95},{20,"Lu",82},{21,"Song",76},{22,"Wu",88}};
STN *head,*p,*q;
int i;
head=NULL;
q=NULL;
for(i=0;i<13;i++)
{
p=(STN *)malloc(sizeof(STN));
p->num=a[i].num;
p->name=a[i].name;
p->grade=a[i].grade;
p->next=NULL;
if(head==NULL)
head=p;
else q->next=p;
q=p;
}
printf("学号(num)姓名(name)成绩(grade)\n");
p=head;
while(p!=NULL)
{
printf(" %-.2d %-7s %5d\n",p->num,p->name,p->grade);
q=p;
p=p->next;
free(q);
}
printf("\n");
}后边不知道怎样将名字那一块儿弄。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询