一个,C语言,指针、结构体和链表方面的简单的程序,帮我改错就行,请注释和修正,,发源代码给我,谢谢
LIBCD.lib(crt0.obj):errorLNK2001:unresolvedexternalsymbol_mainDebug/pro8_6666.exe:fat...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/pro8_6666.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
pro8_6666.exe - 1 error(s), 0 warning(s)
#include<malloc.h>
#include<stdio.h>
#include<string.h>
struct Student{
int Student_ID;
char name[12];
int score;
struct Student *next;
};
void sort(struct Student *p)
{
int i,j;
struct Student temp;
for(i=0;i<2;i++)//bubble
{
for(j=i+1;j<2;j++)
{
if(p[j].score<p[j+1].score)
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
}
}
}
}
struct Student * score_list()
{
int i,n;
struct Student *head=NULL,*p1,*p2=NULL;
void sort(struct Student *p);
printf("请输入学生数量n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
if((p1=malloc(sizeof(struct Student)))==NULL)
{
printf("no\n");
exit(0);
}
p1->next=NULL;
printf("请输入第%d位学生的学号、姓名、分数(以空格隔开,以回车结束):",i);
scanf("%d%s%d",&p1->Student_ID,p1->name,&p1->score);
if(i==1)head=p1;else p2->next=p1;
p2=p1;
}
sort(head);
p1=head;
for(i=0;i<n;i++)printf("%-6d%-9s%-6d\n",p1->Student_ID,p1->name,p1->score);
return head;
} 展开
Debug/pro8_6666.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
pro8_6666.exe - 1 error(s), 0 warning(s)
#include<malloc.h>
#include<stdio.h>
#include<string.h>
struct Student{
int Student_ID;
char name[12];
int score;
struct Student *next;
};
void sort(struct Student *p)
{
int i,j;
struct Student temp;
for(i=0;i<2;i++)//bubble
{
for(j=i+1;j<2;j++)
{
if(p[j].score<p[j+1].score)
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
}
}
}
}
struct Student * score_list()
{
int i,n;
struct Student *head=NULL,*p1,*p2=NULL;
void sort(struct Student *p);
printf("请输入学生数量n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
if((p1=malloc(sizeof(struct Student)))==NULL)
{
printf("no\n");
exit(0);
}
p1->next=NULL;
printf("请输入第%d位学生的学号、姓名、分数(以空格隔开,以回车结束):",i);
scanf("%d%s%d",&p1->Student_ID,p1->name,&p1->score);
if(i==1)head=p1;else p2->next=p1;
p2=p1;
}
sort(head);
p1=head;
for(i=0;i<n;i++)printf("%-6d%-9s%-6d\n",p1->Student_ID,p1->name,p1->score);
return head;
} 展开
展开全部
#include<stdlib.h>
#include<stdio.h>
//#include<string.h>
struct Student {
int Student_ID;
char name[12];
int score;
struct Student *next;
};
void Sort(Student *head) {//类选择排序,交换结点位置,并非交换结点数据。
Student *p = head,*pt,*q,*s,*st;
while(p->next) {
q = p->next;
s = q;
while(q->next) { // 以学号升排序
if(p->next->Student_ID > q->next->Student_ID) {
s = q;
st = s->next;
}
q = q->next;
}
if(s != p->next) {
pt = p->next;
p->next = s->next;
s->next = st->next->next;
p->next->next = pt;
}
p = p->next;
}
}
struct Student *score_list() {
int i,n;
struct Student *head,*p;
void sort(struct Student *p);
head = p = (struct Student *)malloc(sizeof(struct Student));
if(p == NULL) {
printf("动态内存申请失败!\n");
exit(0);
}
printf("请输入学生数量n: ");
scanf("%d",&n);
for(i = 0;i < n;i++) {
if((p->next = (struct Student *)malloc(sizeof(struct Student))) == NULL) {
printf("no\n");
exit(0);
}
printf("请输入第%d位学生的学号、姓名、分数(空格隔开):",i + 1);
scanf("%d%s%d",&p->next->Student_ID,p->next->name,&p->next->score);
p = p->next;
}
p->next = NULL;
sort(head);
p = head->next;
while(p) {
printf("%-d%\t-s%\t-d\n",p->Student_ID,p->name,p->score);
p = p->next;
}
return head;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询