| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 651 人关注过本帖
标题:求高手帮我改一下里面的错误
只看楼主 加入收藏
yanghongyoyo
Rank: 1
等 级:禁止访问
帖 子:18
专家分:3
注 册:2013-10-26
结帖率:100%
收藏
已结贴  问题点数:11 回复次数:7 
求高手帮我改一下里面的错误
#include "stdio.h"/*定义学生结构体*/
struct Student
{
    char ID[20];
    char Name[20];
    float Mark1;
    float Mark2;
    float Mark3;
    float Average;
};/*声明学生数组及学生数量*/
struct Student students[1000];
int num=0;/*求平均值*/
float Avg(struct Student stu)
{
    return (stu.Mark1+stu.Mark2+stu.Mark3)/3;
}/*通过学号返回数组下标*/
int Student_SearchByIndex(char() id[])
{
    int i;
for (i=0;i<num;i++)
{
    if (strcmp(students[i].ID,id)==0)
    {
        return i;
}
}
return -1;
}/*通过姓名返回数组下标*/
int Student_SearchByName(char name[])
{
    int i;
for (i=0;i<num;i++)
{
    if (strcmp(students[i].Name,name)==0)
    {
        return i;
}
}return -1;
}/*显示单条学生记录*/
void Student_DisplaySingle(int index)
{
    printf("%10s%10s%8s%8s%8s%10s\n","学号","姓名","成绩","成绩","成绩","平均成绩");
    printf("-------------------------------------------------------------\n");
    printf("%10s%10s%8.2f%8.2f%8.2f%10.2f\n",students[index].ID,students[index].Name,students[index].Mark1,students[index].Mark2,students[index].Mark3,students[index].Average);
}
/*插入学生信息*/
void Student_Insert()
{
    while(1){printf("请输入学号:");
    scanf("%s",&students[num].ID);
    getchar()();
    printf("请输入姓名:");
    scanf("%s",&students[num].Name);
    getchar()();
    printf("请输入成绩:");
    scanf("%f",&students[num].Mark1);
    getchar()();printf("请输入成绩:");
    scanf("%f",&students[num].Mark2);
    getchar();printf("请输入成绩:");
    scanf("%f",&students[num].Mark3);
    getchar();students[num].Average=Avg(students[num]);
    num++;printf("是否继续?(y/n)");
    if (getchar()=='n')
    {
        break;
}
}
}
/*修改学生信息*/
void Student_Modify()
{
    float mark1,mark2,mark3;while(1)
    {
        char id[20];int index;printf("请输入要修改的学生的学号:");
        scanf("%s",&id);
        getchar();
        index=Student_SearchByIndex(id);
        if (index==-1)
        {
            printf("学生不存在!\n");
}
        else
        {
            printf("你要修改的学生信息为:\n");
            Student_DisplaySingle(index);
            printf("-- 请输入新值--\n");
            printf("请输入学号:");
            scanf("%s",&students[index].ID);
            getchar();
            printf("请输入姓名:");
            scanf("%s",&students[index].Name);
            getchar();printf("请输入成绩:");
            scanf("%f",&students[index].Mark1);
            getchar();printf("请输入成绩:");
            scanf("%f",&students[index].Mark2);
            getchar();
            printf("请输入成绩:");
            scanf("%f",&students[index].Mark3);
            getchar();
            students[index].Average=Avg(students[index]);
        }
        printf("是否继续?(y/n)");
        if (getchar()=='n')
        {
            break;
}
}
}
/*删除学生信息*/
void Student_Delete()
{
    int i;while(1)
    {
        char id[20];
        int index;
        printf("请输入要删除的学生的学号:");
        scanf("%s",&id);getchar();
        index=Student_SearchByIndex(id);
        if (index==-1)
        {
            printf("学生不存在!\n");
}
        else
        {
            printf("你要删除的学生信息为:\n");
            Student_DisplaySingle(index);
            printf("是否真的要删除?(y/n)");
            if (getchar()=='y')
            {
                for (i=index;i<num-1;i++)
                {
                    students[i]=students[i+1];
}
                num--;
}
            getchar();
}
        printf("是否继续?(y/n)");
        if (getchar()=='n'){break;
}
}
}
/*按姓名查询*/
void Student_Select()
{
    while(1)
    {
        char name[20];
        int index;
        printf("请输入要查询的学生的姓名:");
        scanf("%s",&name);
        getchar();
        index=Student_SearchByName(name);
        if (index==-1)
        {
            printf("学生不存在!\n");
}
        else
        {
            printf("你要查询的学生信息为:\n");
            Student_DisplaySingle(index);
}
        printf("是否继续?(y/n)");
        if (getchar()=='n')
        {
            break;
}
}
}
/*按平均值排序*/
void Student_SortByAverage()
{
    int i,j;
    struct Student tmp;
    for (i=0;i<num;i++)
    {
        for (j=1;j<num-i;j++)
        {
            if (students[j-1].Average<students[j].Average)
            {
                tmp=students[j-1];
                students[j-1]=students[j];
                students[j]=tmp;
}
}
}
}
/*显示学生信息*/
void Student_Display()
{
    int i;
    printf("%10s%10s%8s%8s%8s%10s\n","学号","姓名","成绩","成绩","成绩","平均成绩");
    printf("-------------------------------------------------------------\n");
    for (i=0;i<num;i++)
    {
        printf("%10s%10s%8.2f%8.2f%8.2f%10.2f\n",students[i].ID,students[i].Name,students[i].Mark1,students[i].Mark2,students[i].Mark3,students[i].Average);
}
}
/*将学生信息从文件读出*/
void IO_ReadInfo()
{
    FILE *fp;int i;
    if ((fp=fopen("Database.txt","rb"))==NULL)
    {
        printf("不能打开文件!\n");
        return;
}
    if (fread(&num,sizeof(int),1,fp)!=1)
    {
        num=-1;
}
    else
    {
        for(i=0;i<num;i++)
        {
            fread(&students[i],sizeof(struct Student),1,fp);
}
}
    fclose(fp);
}
/*将学生信息写入文件*/
void IO_WriteInfo()
{
    FILE *fp;int i;
    if ((fp=fopen("Database.txt","wb"))==NULL)
    {
        printf("不能打开文件!\n");
        return;
}
    if (fwrite(&num,sizeof(int),1,fp)!=1)
    {
        printf("写入文件错误!\n");
}
    for (i=0;i<num;i++)
    {
        if (fwrite(&students[i],sizeof(struct Student),1,fp)!=1)
        {
            printf("写入文件错误!\n");
}
}
    fclose(fp);
}
/*主程序*/
main()
{
    int choice;IO_ReadInfo();
while(1)
{/*主菜单*/printf("\n------ 学生成绩管理系统------\n");
printf("1. 增加学生记录\n");
printf("2. 修改学生记录\n");
printf("3. 删除学生记录\n");
printf("4. 按姓名查询学生记录\n");
printf("5. 按平均成绩排序\n");
printf("6. 退出\n");
printf("请选择(1-6):");
scanf("%d",&choice);getchar();
switch(choice)
{
case 1:Student_Insert();break;
case 2:Student_Modify();break;
case 3:Student_Delete();break;
case 4:Student_Select();break;
case 5:Student_SortByAverage();
    Student_Display();break;
case 6:exit();break;
}
IO_WriteInfo();
}
}
搜索更多相关主题的帖子: include return 结构体 平均值 
2014-01-06 08:55
韶志
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:斗气大陆
等 级:贵宾
威 望:44
帖 子:2223
专家分:13592
注 册:2013-3-22
收藏
得分:2 
错误能具体说下么...

三十年河东,三十年河西,莫欺少年穷!
2014-01-06 09:14
yanghongyoyo
Rank: 1
等 级:禁止访问
帖 子:18
专家分:3
注 册:2013-10-26
收藏
得分:0 
回复 2楼 韶志
放在编译器里有几个错误
2014-01-06 10:05
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:2 
比照错误信息修改吧

大多数编译器都提供错误代码所在的行数  错误信息的内容 等

DO IT YOURSELF !
2014-01-06 10:14
yanghongyoyo
Rank: 1
等 级:禁止访问
帖 子:18
专家分:3
注 册:2013-10-26
收藏
得分:0 
那些编译器的错误理解不了  不知道怎么改
2014-01-06 10:57
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
这有啥看不懂的  无语

举例:

程序代码:
D:\c_source\tt1\main\main.c|17|error: expected `)' before "id"|
D:\c_source\tt1\main\main.c|18|error: expected `,' or `;' before '{' token|
D:\c_source\tt1\main\main.c||In function `int Student_SearchByName(char*)':|
D:\c_source\tt1\main\main.c|34|error: `strcmp' undeclared (first use this function)|
D:\c_source\tt1\main\main.c|34|error: (Each undeclared identifier is reported only once for each function it appears in.)|
D:\c_source\tt1\main\main.c||In function `void Student_Insert()':|
D:\c_source\tt1\main\main.c|50|warning: char format, different type arg (arg 2)|
D:\c_source\tt1\main\main.c|51|error: `getchar()' cannot be used as a function|
D:\c_source\tt1\main\main.c|53|warning: char format, different type arg (arg 2)|
D:\c_source\tt1\main\main.c|54|error: `getchar()' cannot be used as a function|
D:\c_source\tt1\main\main.c|57|error: `getchar()' cannot be used as a function|
D:\c_source\tt1\main\main.c||In function `void Student_Modify()':|
D:\c_source\tt1\main\main.c|75|warning: char format, different type arg (arg 2)|
D:\c_source\tt1\main\main.c|77|error: `Student_SearchByIndex' cannot be used as a function|
D:\c_source\tt1\main\main.c|88|warning: char format, different type arg (arg 2)|
D:\c_source\tt1\main\main.c|91|warning: char format, different type arg (arg 2)|
D:\c_source\tt1\main\main.c|72|warning: unused variable 'mark1'|
D:\c_source\tt1\main\main.c|72|warning: unused variable 'mark2'|
D:\c_source\tt1\main\main.c|72|warning: unused variable 'mark3'|
D:\c_source\tt1\main\main.c||In function `void Student_Delete()':|
D:\c_source\tt1\main\main.c|117|warning: char format, different type arg (arg 2)|
D:\c_source\tt1\main\main.c|118|error: `Student_SearchByIndex' cannot be used as a function|
D:\c_source\tt1\main\main.c||In function `void Student_Select()':|
D:\c_source\tt1\main\main.c|151|warning: char format, different type arg (arg 2)|
D:\c_source\tt1\main\main.c|245|warning: ISO C++ forbids declaration of `main' with no type|
D:\c_source\tt1\main\main.c||In function `int main()':|
D:\c_source\tt1\main\main.c|265|error: `exit' undeclared (first use this function)|
||=== Build finished: 10 errors, 11 warnings (0 minutes, 1 seconds) ===|



看看你第17行是什么东西

int Student_SearchByIndex(char() id[])
有这么声明函数的吗  没见过

DO IT YOURSELF !
2014-01-06 11:01
不是人
Rank: 1
等 级:新手上路
帖 子:4
专家分:9
注 册:2014-1-7
收藏
得分:2 
2014-01-07 14:04
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:2 
踏踏实实的学习才行啊

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2014-01-07 14:07
快速回复:求高手帮我改一下里面的错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018563 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved