#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN sizeof(struct Student)
struct Student{
char name[10];
int number;
struct Student *next;
};
struct Student * InitList();
void CreatList(struct Student *head);
void PrintList(struct Student *head);
struct Student GetListElm(struct Student *head,int i);
int main(void){
struct Student *head,student;
head=InitList();
CreatList(head);
PrintList(head);
student=GetListElm(head,2);
printf("%s",student.name);
return 0;
}
struct Student *InitList() {
struct Student *head=NULL;
head=(struct Student*)malloc(LEN);
head->next=NULL;
return head;
}
void CreatList(struct Student *head) {
struct Student *pre=NULL,*cur=NULL;
int number,n=0;
char name[10];
pre=head;
while (1){
printf("请输入学号(-1结束输入):\n");
scanf("%d",&number);
if (number==-1){
break;
}
getchar();
printf("请输入姓名:");
gets(name);
cur=(struct Student*)malloc(LEN);
cur->number=number;
strcpy(cur->name,name);
pre->next=cur;
pre=cur;
n++;
}
head->number=n;
cur->next=NULL;
}
void PrintList(struct Student *head) {
struct Student *cur=head->next;
printf("共有%d条数据\n",head->number);
while (cur!=NULL){
printf("姓名:%s\t",cur->name);
printf("学号:%d\n",cur->number);
cur=cur->next;
}
}
struct Student GetListElm(struct Student *head, int i) {
struct Student *cur=head->next;
int length=head->number,j;
if (i>length){
printf("您所查找的编号超出了链表范围");
system("pause");
exit(0);
}
for(j=0;j<i;j++){
cur=cur->next;
}
return *cur;
}
下面是软件的提示,我在百度上寻找不到答案,谢谢大佬们
Error during pretty printers setup: Undefined info command: "pretty-printer". Try "help info".
Some features and performance optimizations will not be available.
D:\practice\ManageSystem\cmake-build-debug\ManageSystem.exe