C语言常见错误
- 格式:doc
- 大小:174.00 KB
- 文档页数:21
一·
不知道你用的是什么编译器,我帮你搞定了。
头文件#include "stdafx.h"必须放在第一位;清屏的函数也要头文件#include "conio.h";input 类型是int型的,main函数也要弄成int类型的。还有char No[100];你要定义成数组撒,基本上有错的地方都帮你弄完了,完全没错误,能实现你的功能了,分给我吧,呵呵。
// 3.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "stdio.h" /*输入输出函数*/
#include "string.h" /*字符串函数*/
#include "malloc.h" /*动态内存分配*/
#include "stdlib.h" /*杂项及内存分配函数*/
#include "conio.h"
typedef struct Node{
char No[40];
char Name[40];
float Math;
float Chinese;
float sum;
struct Node *prior;
struct Node *next;
}Node,*Link;
Link head, s1, s2;
struct Node *s;
int n = 0, k = 0;
void shuru(); /*函数调用声明*/
void chaxun();
void paixu();
void xiugai();
void shanchu();
int main() /*主函数*/
{
int input;
// clrscr(); /*清屏函数*/
do{
printf(" The inquire system for the students' scores\n ");
printf("************************************************\n");
printf(" 1>shuru\n "); printf(" 2>chaxun\n "); printf(" 3>paixu\n "); printf(" 4>xiugai\n "); printf(" 5>shanchu\n "); printf("************************************************\n");
printf("please give me a choice:1,2,3,4,5,6\n ");
scanf("%d",&input);
switch(input)
{
case 1:shuru();break;
case 2:chaxun();break;
case 3:paixu();break;
case 4:xiugai();break;
case 5:shanchu();break;
default:printf("Something is wrong!\n");
}
}while(input);
}
void shuru() /*学生成绩输入*/ {
int m;
head = (Link)malloc(sizeof(Node));
s = head;
do
{
s->next = (Link)malloc(sizeof(Node));
s = s->next;
s->next = NULL;
printf("Please input the No,Name,Math,Chinese\n");
scanf("%s%s%f%f",s->No,s->Name,&s->Math,&s->Chinese);
s->sum = s->Math+s->Chinese;
n++;
printf("Do you want to go on? 1 = yes,0 = no\n");
scanf("%d",&m);
}while(m);
}
void chaxun() /*学生成绩查询*/
{
int m;
char No[100];
do
{
s1 = head->next;
printf("Please input the No\n");
scanf("%s",No);
while((strcmp(s1->No,No)) != 0 && (s1 != NULL)) /*比较两个字符串,大小相等时值为0*/
{
s1=s1->next;
}
printf("****No****Name****Math****Chinese*******\n");
if(s1!=NULL)
{
k=1;
printf("%s%s%f%f%f",s1->No,s1->Name,s1->Math,s1->Chinese,s1->sum);
}
else
{
k=0;
printf("your input is wrong!\n");
}
printf("Do you want to go on? 1 = yes,0 = no\n");
scanf("%d",&m);
}while(m);
}
void paixu() /*学生成绩排序*/
{
int x, y, z, m=1;
float sum[50], n;
s2 = head->next;
x = 0;
while(s2!=NULL)