良辰好景虚设w
2016-03-23 05:23
采纳率: 100%
浏览 1.6k
已采纳

关于C语言结构体指针数组的问题


//结构体
struct student
{
    int iNum;
    char cName[16];
    float fChineseScore;
    float fMathScore;
    float fEnglishScore;
};
typedef struct student STUDENT;

//输入
void InputTranscript(STUDENT MyClass[], int num)
{
    int i;
    printf("请输入学生的成绩信息:\n");
    for (i = 0; i < num; i++)
    {
        scanf("%d %s %f %f %f", &MyClass[i].iNum, MyClass[i].cName,
        &MyClass[i].fChineseScore, &MyClass[i].fMathScore, &MyClass[i].fEnglishScore);
    }
}

//输出单体
void DisplayTranscriptOne(STUDENT MyScore)
{
    int i;
    STUDENT *p1 = MyScore;
    printf("请输入需要显示成绩信息的学生的序号:");
    scanf("%d", &i);
    printf("输出学生的成绩信息:\n");
    printf("%d %s %f %f %f", (p1 + i) -> iNum, (p1 + i) -> cName,
    (p1 + i) -> fChineseScore, (p1 + i) -> fMathScore, (p1 + i) -> fEnglishScore);
}

//输出全体
void DisplayTranscriptAll(STUDENT *MyClass, int num)
{
    printf("输出全体学生的成绩信息\n");
    for (; MyClass < MyClass + num; MyClass++)
    {
        printf("%d %s %f %f %f", MyClass -> iNum, MyClass -> cName, 
        MyClass -> fChineseScore, MyClass -> fMathScore, MyClass -> fEnglishScore);
    }
}

//修改
void ModifyOne(STUDENT *MyInfo)
{
    int i;
    printf("请输入需修改个人信息的学生的序号:");
    scanf("%d", &i);
    printf("请继续输入修改后的信息:");
    scanf("%d %s %f %f %f", (MyInfo + i) -> iNum, &(MyInfo + i) -> cName, 
    &(MyInfo + i) -> fChineseScore, &(MyInfo + i) -> fMathScore, &(MyInfo + i) -> fEnglishScore);
}

void main(void)
{
    STUDENT sTranscript[10]; 
    InputTranscript(sTranscript, 10);
    DisplayTranscriptOne(sTranscript);
    DisplayTranscriptAll(*sTranscript, 10);
    ModifyOne(*sTranscript);
}


--------------------Configuration: 4 - Win32 Debug--------------------
Compiling...
4.c
C:\Users\20453\Desktop\王俊森\4\4.c(30) : error C2115: 'initializing' : incompatible types
C:\Users\20453\Desktop\王俊森\4\4.c(64) : error C2115: 'function' : incompatible types
C:\Users\20453\Desktop\王俊森\4\4.c(64) : warning C4024: 'DisplayTranscriptOne' : different types for formal and actual parameter 1
C:\Users\20453\Desktop\王俊森\4\4.c(65) : error C2115: 'function' : incompatible types
C:\Users\20453\Desktop\王俊森\4\4.c(65) : warning C4024: 'DisplayTranscriptAll' : different types for formal and actual parameter 1
C:\Users\20453\Desktop\王俊森\4\4.c(66) : error C2115: 'function' : incompatible types
C:\Users\20453\Desktop\王俊森\4\4.c(66) : warning C4024: 'ModifyOne' : different types for formal and actual parameter 1
Error executing cl.exe.

4.obj - 4 error(s), 3 warning(s)

求大神帮我看看这程序哪错了,怎么改,感激不尽

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 小灸舞 2016-03-23 05:58
    已采纳

    传进去的实参和函数的形参类型不一样

    #include<stdio.h>
    using namespace std;
    
    struct student
    {
        int iNum;
        char cName[16];
        float fChineseScore;
        float fMathScore;
        float fEnglishScore;
    };
    typedef struct student STUDENT;
    
    //输入
    void InputTranscript(STUDENT MyClass[], int num)
    {
        int i;
        printf("请输入学生的成绩信息:\n");
        for (i = 0; i < num; i++)
        {
            scanf("%d %s %f %f %f", &MyClass[i].iNum, MyClass[i].cName,
            &MyClass[i].fChineseScore, &MyClass[i].fMathScore, &MyClass[i].fEnglishScore);
        }
    }
    
    //输出单体
    void DisplayTranscriptOne(STUDENT *MyScore)
    {
        int i;
        STUDENT *p1 = MyScore;
        printf("请输入需要显示成绩信息的学生的序号:");
        scanf("%d", &i);
        printf("输出学生的成绩信息:\n");
        printf("%d %s %f %f %f", (p1 + i) -> iNum, (p1 + i) -> cName,
        (p1 + i) -> fChineseScore, (p1 + i) -> fMathScore, (p1 + i) -> fEnglishScore);
    }
    
    //输出全体
    void DisplayTranscriptAll(STUDENT *MyClass, int num)
    {
        printf("输出全体学生的成绩信息\n");
        for (; MyClass < MyClass + num; MyClass++)
        {
            printf("%d %s %f %f %f", MyClass -> iNum, MyClass -> cName, 
            MyClass -> fChineseScore, MyClass -> fMathScore, MyClass -> fEnglishScore);
        }
    }
    
    //修改
    void ModifyOne(STUDENT *MyInfo)
    {
        int i;
        printf("请输入需修改个人信息的学生的序号:");
        scanf("%d", &i);
        printf("请继续输入修改后的信息:");
        scanf("%d %s %f %f %f", (MyInfo + i) -> iNum, &(MyInfo + i) -> cName, 
        &(MyInfo + i) -> fChineseScore, &(MyInfo + i) -> fMathScore, &(MyInfo + i) -> fEnglishScore);
    }
    
    void main(void)
    {
        STUDENT sTranscript[10]; 
        InputTranscript(sTranscript, 10);
        DisplayTranscriptOne(&sTranscript[0]);
        DisplayTranscriptAll(sTranscript, 10);
        ModifyOne(sTranscript);
    } 
    
    点赞 打赏 评论
  • 小灸舞 2016-03-23 09:38

    图片说明
    我这里输出一个出是对的,输出全体有点问题

    点赞 打赏 评论
  • 良辰好景虚设w 2016-03-23 10:58
     #include<stdio.h>
    
    //结构体
    struct student
    {
        int iNum;
        char cName[16];
        float fChineseScore;
        float fMathScore;
        float fEnglishScore;
    };
    typedef struct student STUDENT;
    
    //输入
    void InputTranscript(STUDENT MyClass[], int num)
    {
        int i;
        printf("请输入学生的成绩信息:\n");
        for (i = 0; i < num; i++)
        {
            scanf("%d %s %f %f %f", &MyClass[i].iNum, MyClass[i].cName,
            &MyClass[i].fChineseScore, &MyClass[i].fMathScore, &MyClass[i].fEnglishScore);
        }
    }
    
    //输出单体
    void DisplayTranscriptOne(STUDENT *MyScore)
    {
        int i;
        printf("请输入需要显示成绩信息的学生的序号:");
        scanf("%d", &i);
        printf("输出学生的成绩信息:\n");
        printf("%d %s %.2f %.2f %.2f\n", (MyScore + i - 1) -> iNum, (MyScore + i - 1) -> cName,
        (MyScore + i - 1) -> fChineseScore, (MyScore + i - 1) -> fMathScore, (MyScore + i - 1) -> fEnglishScore);
    }
    
    //输出全体
    void DisplayTranscriptAll(STUDENT *MyClass, int num)
    {
        int i;
        printf("输出全体学生的成绩信息:\n");
        for (i = 0; i < num; i++)
        {
            printf("%d %s %.2f %.2f %.2f\n", (MyClass + i) -> iNum, (MyClass + i) -> cName, 
            (MyClass + i) -> fChineseScore, (MyClass + i) -> fMathScore, (MyClass + i) -> fEnglishScore);
        }
    }
    
    //修改
    void ModifyOne(STUDENT *MyInfo)
    {
        int i;
        printf("请输入需修改个人信息的学生的序号:\n");
        scanf("%d", &i);
        printf("请继续输入修改后的信息:\n");
        scanf("%d %s %f %f %f", &(MyInfo + i - 1) -> iNum, (MyInfo + i - 1) -> cName, 
        &(MyInfo + i - 1) -> fChineseScore, &(MyInfo + i - 1) -> fMathScore, &(MyInfo + i - 1) -> fEnglishScore);
    }
    
    void main(void)
    {
        STUDENT sTranscript[10]; 
        InputTranscript(sTranscript, 10);
        DisplayTranscriptOne(sTranscript);
        DisplayTranscriptAll(sTranscript, 10);
        ModifyOne(sTranscript);
        DisplayTranscriptOne(sTranscript);
    }
    

    好了我改好了 运行上也没错误了

    点赞 打赏 评论

相关推荐 更多相似问题