|
楼主 |
发表于 2004-6-11 16:14:51
|
显示全部楼层
[quote:ad1762d411="sagaeon"][free@sagaeon program]$ gcc -Wall test15.c
test15.c: In function `main':
test15.c:55: warning: too few arguments for format
test15.c:83: warning: implicit declaration of function `Print_Student'
test15.c:104: warning: implicit declaration of function `LocationName_Student'
test15.c:109: warning: implicit declaration of function `LocateNum_Student'
test15.c:126: warning: implicit declaration of function `Delete_File'
test15.c: In function `Print_Student':
test15.c:271: warning: `return' with no value, in function returning non-void
test15.c: In function `LocationName_Student':
test15.c:410: warning: unused variable `diName'
test15.c:411: warning: unused variable `num'
test15.c:452: warning: control reaches end of non-void function
test15.c: In function `LocateNum_Student':
test15.c:488: warning: control reaches end of non-void function
test15.c: In function `Destroy_Students':
test15.c:500: warning: `return' with no value, in function returning non-void
test15.c:515: warning: `return' with no value, in function returning non-void
test15.c: In function `Delete_File':
test15.c:588: warning: control reaches end of non-void function
我编译还是不行?[/quote]
[code:1]
/*简单学生信息表v2.0*/
#include <stdio.h> /*基本输入输出*/
#include <string.h> /*字符串函数*/
#include <stdlib.h>
#define true 1
#define false 0
#define maxsize 20 /*姓名长度*/
typedef struct courseInfo /*课程结构体*/
{
float chinese;
float english;
float math;
} courseTp;
typedef struct dateInfo /*出生日期结构体*/
{
int year;
int month;
int day;
} dateTp;
typedef struct node /*学生信息结构体*/
{
int num; /*学号*/
char name[maxsize]; /*姓名*/
char sex[10]; /*性别*/
struct dateInfo date; /*出身日期*/
int age; /*年龄*/
struct courseInfo course; /*课程*/
struct node *next;
} Student;
Student* Initiate_Student(); /*初始化表*/
Student* Create_Student(Student *head); /*建表*/
Student* Find_Student(Student *head, int num); /*查找结点位置*/
Student* Insert_Student(Student *head); /*插入结点*/
Student* Delete_Student(Student *head, int i); /*删除结点*/
Student* Destroy_Students(Student *head); /*销毁表*/
Student* Load_Students(Student *head); /*读取表*/
int Print_Student(Student *head); /*屏显表*/
int LocationName_Student(Student *head); /*定位(字符串)*/
int Save_Students(Student *head); /*保存*/
int LocateNum_Student(Student *head, int num); /*定位(数字)*/
int main (void)
{
FILE *fp;
Student *head, *p;
int choose, num;
float average, chinese, math, english;
head = Initiate_Student();
printf("%s\n%s\n%s\n%s",
"*************************************************",
"* 简单学生信息表系统 for lluct. *",
"* Simple students information system for lluct *",
"*************************************************");
if ((fp = fopen ("students.dat", "r")) == NULL)
{
head = Create_Student(head);
}
else
head = Load_Students(head);
while (true)
{
printf("\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s",
"###菜单列表 MENU###",
"1:查看学生列表 SHOW LIST OF STUDENTS",
"2:查找学生序号 SEARCH LOCATION OF STUDENT",
"3:按姓名查找 SEARCH NAME OF STUDENT",
"4:按学号查找 SEARCH NO. OF STUDENT",
"5:插入学生信息 INSERT INFO OF STUDENT",
"6:删除学生信息 DELETE INFO OF STUDENT",
"7:保存当前信息 SAVE",
"8:读取文件信息 LOAD",
"0:退出 EXIT",
"请选择 PLEASE CHOOSE:");
scanf("%d", &choose);
switch (choose)
{
case 1:
Print_Student(head);
break;
case 2:
printf("\n请输入要查找的序号 INPUT LOCATION FOR SEARCH:");
scanf("%d", &num);
p = Find_Student(head, num);
chinese = p -> course.chinese;
english = p -> course.english;
math = p -> course.math;
average = (chinese+english+math)/3;
printf("\n该序号的学生信息为 NOW LIST:\n\n");
printf("LOC. NO. NAME SEX BORN AGE CH. MATH EN. AVE. \n");
printf("序号 学号 姓 名 性别 出生日期 年龄 语文 数学 英语 平均分\n");
printf("%4d %4d %6s %4s %4d-%2d-%2d %4d %4g %4g %4g %4g\n",
num, p -> num, p -> name, p ->sex, p -> date.year,
p -> date.month, p -> date.day, p -> age,
p -> course.chinese, p -> course.math, p -> course.english,
average);
printf("\n");
break;
case 3:
LocationName_Student(head);
break;
case 4:
printf("\n请输入要查找的学生学号 INPUT SNO FOR SEARCH:");
scanf("%d", &num);
LocateNum_Student(head, num);
break;
case 5:
head = Insert_Student(head);
break;
case 6:
printf("\n请输入要删除的位置(序号) INPUT LOCATION FOR DELETE:");
scanf("%d", &num);
head = Delete_Student(head, num);
break;
case 7:
Save_Students(head);
break;
case 8:
head = Load_Students(head);
break;
case 0:
Destroy_Students(head);
exit(0);
default:
printf("\n选择错误! CHOOSE ERROR!\n");
}
}
}
Student* Initiate_Student (void)
{
Student *head;
head = (Student *) malloc (sizeof(Student));
head -> next = NULL;
return (head);
}
Student* Create_Student (Student *head)
{
Student *new, *end;
int age, num;
int year, month, day;
float chinese, english, math;
char input;
int count;
int choose;
int nextStu = true, sexFin = true, dateFin = true;
end = head;
while (nextStu)
{
sexFin = true, dateFin = true;
count = 0;
new = (Student *) malloc (sizeof(Student));
printf("\n请输入学生学号(四位) NO.(MAX 4):");
scanf("%d", &num);
getchar();
printf("请输入学生姓名 NAME:");
while ((input = getchar()) != '\n')
{
new -> name[count] = input;
count++;
}
new -> name[count] = '\0';
while (sexFin)
{
printf("请选择学生性别(1:男性 2:女性) SEX(1:MALE 2:FEMALE):");
scanf("%d", &choose);
switch (choose)
{
case 1:
strcpy (new -> sex, "男 M");
sexFin = false;
break;
case 2:
strcpy (new -> sex, "女 F");
sexFin = false;
break;
default:
printf("\n选择错误,请重新选择! ERROR\n");
}
}
while (dateFin)
{
printf("请输入学生生日(年-月-日) BORN(YYYY-MM-DD):");
scanf("%d-%d-%d", &year, &month, &day);
if ((year > 2000) || (year < 1949))
printf("\n年份输入错误,请重新输入! ERROR\n");
else if ((month >12) || (month < 1))
printf("\n月份输入错误,请重新输入! ERROR\n");
else if ((day > 31) || (day < 1))
printf("\n天数输入错误,请重新输入! ERROR\n");
else
dateFin = false;
}
printf("请输入学生年龄 AGE:");
scanf("%d", &age);
printf("请输入语文成绩(可带小数) SCORES OF CHINESE:");
scanf("%f", &chinese);
printf("请输入数学成绩(同上) SCORES OF MATH:");
scanf("%f", &math);
printf("请输入英语成绩(同上) SCORES OF ENGLISH:");
scanf("%f", &english);
new -> num = num;
new -> date.year = year;
new -> date.month = month;
new -> date.day = day;
new -> age = age;
new -> course.chinese = chinese;
new -> course.math = math;
new -> course.english = english;
end -> next = new;
end = new;
getchar();
printf("\n是否继续输入(Y/N) CONTINUE?");
scanf("%c", &input);
if (input == 'Y' || input == 'y')
nextStu = true;
else
nextStu = false;
}
return (head);
}
int Print_Student (Student *head)
{
Student *p;
int j = 0;
float average, chinese, english, math;
p = head;
printf("\n目前学生列表 NOW LIST:\n\n");
printf("LOC. NO. NAME SEX BORN AGE CH. MATH EN. AVE.\n");
printf("序号 学号 姓 名 性别 出生日期 年龄 语文 数学 英语 平均分\n");
printf("-------------------------------------------------------------------------------\n");
if (head != NULL)
{
p = p -> next;
while (p != NULL)
{
chinese = p -> course.chinese;
english = p -> course.english;
math = p -> course.math;
average = (chinese+english+math)/3;
printf("(%d)", j + 1);
j++;
printf(" %d %6s %4s %4d-%2d-%2d %4d %4g %4g %4g %4g\n",
p -> num, p -> name, p ->sex, p -> date.year,
p -> date.month, p -> date.day, p -> age,
p -> course.chinese, p -> course.math, p -> course.english,
average);
p = p -> next;
}
}
printf("-------------------------------------------------------------------------------\n");
printf("共有%d个学生 TOTAL %d STUDENT(S).\n\n", j, j);
return false;
}
Student* Find_Student (Student *head, int i)
{
Student *p;
int j = 0;
p = head;
while ((p -> next != NULL) && (j < i))
{
p = p -> next;
j++;
}
if (i == j)
return (p);
else
{
printf("该位置不存在! LOCATION NOT FOUND!\n");
return false;
}
}
Student* Insert_Student (Student *head)
{
Student *p, *s;
int age, num;
int year, month, day;
char input;
float chinese, math, english;
int count;
int sexFin = true, dateFin = true;
int choose, insertLocation;
printf("\n请输入要插入的位置(序号): LOCATION:");
scanf("%d", &insertLocation);
p = Find_Student(head, insertLocation - 1);
if (p == NULL)
{
printf("不存在第%d个位置! LOCATION NOT FOUND\n", insertLocation);
return false;
}
else
{
sexFin = true, dateFin = true;
count = 0;
s = (Student *) malloc (sizeof(Student));
printf("\n请输入学生学号 NO.:");
scanf("%d", &num);
getchar();
printf("请输入学生姓名 NAME:");
while ((input = getchar()) != '\n')
{
s -> name[count] = input;
count++;
}
s -> name[count] = '\0';
while (sexFin)
{
printf("请选择学生性别(1:男性 2:女性) SEX(1:MALE 2:FEMAL):");
scanf("%d", &choose);
switch (choose)
{
case 1:
strcpy (s -> sex, "男 M");
sexFin = false;
break;
case 2:
strcpy (s -> sex, "女 F");
sexFin = false;
break;
default:
printf("\n选择错误,请重新选择! CHOOSE ERROR!\n");
}
}
while (dateFin)
{
printf("请输入学生生日(年-月-日) BORN(YYYY-MM-DD):");
scanf("%d-%d-%d", &year, &month, &day);
if ((year > 2000) || (year < 1949))
printf("\n年份输入错误,请重新输入! ERROR\n");
else if ((month >12) || (month < 1))
printf("\n月份输入错误,请重新输入! ERROR\n");
else if ((day > 31) || (day < 1))
printf("\n天数输入错误,请重新输入! ERROR\n");
else
dateFin = false;
}
printf("请输入学生年龄 AGE:");
scanf("%d", &age);
printf("请输入语文成绩 SCORES OF CHINESE:");
scanf("%f", &chinese);
printf("请输入数学成绩 SCORES OF MATH:");
scanf("%f", &math);
printf("请输入英语成绩 SCORES OF ENGLISH:");
scanf("%f", &english);
s -> num = num;
s -> date.year = year;
s -> date.month = month;
s -> date.day = day;
s -> age = age;
s -> course.chinese = chinese;
s -> course.math = math;
s -> course.english = english;
s -> next = p -> next;
p -> next = s;
}
return (head);
}
Student* Delete_Student (Student *head, int i)
{
Student *p, *s;
p = Find_Student(head, i - 1);
if ((p != NULL) && (p -> next != NULL))
{
s = p -> next;
p -> next = s -> next;
free(s);
}
else
{
printf("不存在第%d个位置! LOCATION NOT FOUND\n", i);
return 0;
}
return (head);
}
int LocationName_Student (Student *head)
{
Student *p;
char input;
char siName[20];
int count = 0, j = 0;
float average, chinese, english, math;
p = head;
getchar();
printf("请输入要查找的姓名 NAME FOR SEARCH:");
while ((input = getchar ()) != '\n')
{
siName[count] = input;
count++;
}
siName[count] = '\0';
while ((p -> next != NULL) && (strcmp(siName, p -> name) != 0))
{
p = p -> next;
j++;
}
if (strcmp (siName, p -> name) == 0)
{
chinese = p -> course.chinese;
english = p -> course.english;
math = p -> course.math;
average = (chinese+english+math)/3;
printf("\n该序号的学生信息为 NOW LIST:\n\n");
printf("LOC. NO. NAME SEX BORN AGE CH. MATH EN. AVE.\n");
printf("序号 学号 姓 名 性别 出生日期 年龄 语文 数学 英语 平均分\n");
printf("%4d %4d %6s %4s %4d-%2d-%2d %4d %4g %4g %4g %4g\n",
j, p -> num, p -> name, p ->sex, p -> date.year,
p -> date.month, p -> date.day, p -> age,
p -> course.chinese, p -> course.math, p -> course.english
, average);
printf("\n");
}
else
{
printf("\n查无此人! STUDENT NOT FOUND\n");
return false;
}
return false;
}
int LocateNum_Student (Student *head, int i)
{
int j = 0;
float average, english, chinese, math;
Student *p;
p = head;
while ((p -> next != NULL) && (p -> num != i))
{
p = p -> next;
j++;
}
if (p -> num == i)
{
chinese = p -> course.chinese;
english = p -> course.english;
math = p -> course.math;
average = (chinese+english+math)/3;
printf("\n该序号的学生信息为 NOW LIST:\n\n");
printf("LOC. NO. NAME SEX BORN AGE CH. MATH EN. AVE.\n");
printf("序号 学号 姓 名 性别 出生日期 年龄 语文 数学 英语 平均分\n");
printf("%4d %4d %6s %4s %d-%d-%d %4d %4g %4g %4g %4g\n",
j, p -> num, p -> name, p ->sex, p -> date.year,
p -> date.month, p -> date.day, p -> age,
p -> course.chinese, p -> course.math, p -> course.english,
average);
printf("\n");
}
else
{
printf("\n查无此人! STUDENT NOT FOUND\n");
return false;
}
return false;
}
Student* Destroy_Students (Student *head)
{
int j = 0;
Student *p;
p = head;
if (head -> next == NULL)
{
free (head);
return 0;
}
else
{
while (p != NULL)
{
j++;
p = p -> next;
}
while (j == 0)
{
head = Delete_Student(head, j);
j--;
}
free(head);
return 0;
}
}
int Save_Students(Student *head)
{
FILE *fp;
int j = 0;
Student *p;
p = head;
if ((fp = fopen("students.dat", "wb")) == NULL)
{
printf("file can not open!\n");
exit(false);
}
while (p != NULL)
{
j++;
p = p -> next;
}
printf("\n文件保存成功! FILE SAVED!\n\n");
fwrite(head, sizeof(Student),j,fp);
fclose(fp);
return 0;
}
Student* Load_Students(Student *head)
{
FILE *fp;
int j = 0;
if ((fp = fopen("students.dat", "r")) == NULL)
{
printf("系统错误! SYSTEM ERROR!\n");
exit(false);
}
printf("\n源文件有几个学生信息 HOW MANY STUDNET IN SOURCE FILES?");
scanf("%d", &j);
j++;
fread(head, sizeof(Student), j , fp);
printf("\n文件读取成功! FILE LOAD\n\n");
fclose(fp);
return (head);
}
[/code:1] |
|