![]() |
#2
lin51616782020-04-08 11:50
|

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//
typedef struct player{
int number;
char name[20];
struct player*next;
}Player;
Player*game(void);
int main ()
{
Player *head;
head=game();
printf("%s",head->name);
return 0;
}
Player*game(void)
{
Player *p1=(Player*)malloc(sizeof(Player));
Player *p2=(Player*)malloc(sizeof(Player));
Player *p3=(Player*)malloc(sizeof(Player));
if(p1!=NULL){
p1->number=1;
strcpy(p1->name,"战士1");
}
if(p1!=NULL){
p2->number=2;
strucp(p2->name,"战士2");
}
if(p1!=NULL){
p3->number=3;
strcpy(p3->name,"战士3");
}
//连接节点
p1->next=p2;
p2->next=p3;//不用p2->next=&p3 因为p3已经是typedef struct player的指针变量存储的就是地址古不需要再取地址
p3->next=NULL;//创建尾节点
Player*head=p1;//创建链表的头节点
return head;
}
#include<stdlib.h>
#include<string.h>
//
typedef struct player{
int number;
char name[20];
struct player*next;
}Player;
Player*game(void);
int main ()
{
Player *head;
head=game();
printf("%s",head->name);
return 0;
}
Player*game(void)
{
Player *p1=(Player*)malloc(sizeof(Player));
Player *p2=(Player*)malloc(sizeof(Player));
Player *p3=(Player*)malloc(sizeof(Player));
if(p1!=NULL){
p1->number=1;
strcpy(p1->name,"战士1");
}
if(p1!=NULL){
p2->number=2;
strucp(p2->name,"战士2");
}
if(p1!=NULL){
p3->number=3;
strcpy(p3->name,"战士3");
}
//连接节点
p1->next=p2;
p2->next=p3;//不用p2->next=&p3 因为p3已经是typedef struct player的指针变量存储的就是地址古不需要再取地址
p3->next=NULL;//创建尾节点
Player*head=p1;//创建链表的头节点
return head;
}