#include <stdio.h>
#include <stdlib.h>
//0x30(48) = '0' 0x39(57) = '9'
#define CLS system("cls")
#define ASK_OP(response) puts("INPUT O = IN Ordinary V = IN VIP Q = QUIT");response = getch();
typedef struct _d{
int num;
int score;
struct _d *next;
} stu_data;
stu_data * stu_inp(stu_data *head); //输入函数,同时做最大最小判断
int main(int argc, char *argv[])
{
stu_data *head = NULL;
head = stu_inp(head);
/*这里可以自己再操作链表,如排序,遍历等等*/
system("PAUSE");
return 0;
}
stu_data * stu_inp(stu_data *head)
{
stu_data *pHead = NULL, *pCur = NULL, *pTail = NULL, *pMax = NULL, *pMin = NULL;
int stnum, stscore, max_score = 0, min_score = 0;
printf("input num & score\n");
scanf("%d %d",&stnum, &stscore); //输入示例 :11+空格+98+回车 表示学号11 成绩98
pHead = head; //结束输入的话可以 -1空格+任意数字+回车
while((stnum != -1)&&(stscore>=0)&&(stscore<=100))
{
if(NULL == pHead)
{
if(NULL == (pHead = (stu_data *)malloc(sizeof(stu_data)))) return pHead;
pHead->num = stnum;
pHead->score = stscore;
pHead->next = NULL;
max_score = stscore;
min_score = stscore;
pMax = pHead;
pMin = pHead;
pCur = pHead;
pTail = pHead;
}
else
{
if(NULL == (pTail = (stu_data *)malloc(sizeof(stu_data)))) return pHead;
pCur->next = pTail;
pTail->num = stnum;
pTail->score = stscore;
pTail->next = NULL;
pCur = pTail;
if(max_score < pCur->score)
{
max_score = pCur->score;
pMax = pCur;
}
else
{
if(min_score > pCur->score)
{
min_score = pCur->score;
pMin = pCur;
}
}
}
CLS;
printf("input num & score\n");
scanf("%d %d",&stnum, &stscore);
}
printf("\n max_score is:%d student num is:%d\n\n", pMax->score, pMax->num);
printf("\n min_score is:%d student num is:%d\n\n", pMin->score, pMin->num);
return pHead;
}
追问在VC6里测试有一处错误 e:\program files\microsoft visual studio\myprojects\22\22.cpp(77) : fatal error C1010: unexpected end of file while looking for precompiled header directive
执行 cl.exe 时出错.
追答你工程属性设置不对,
方法一、右键点击22.cpp 菜单project-》settings里 c++页面,Precomplie header设置为Not Using precomplied headers
方法二、增加头文件 #include “stdafx.h”
以上解决方式网络得到,你自己试试.
或者你新建一个c的工程试试,不要用c++的工程
本回答被提问者采纳