夏日不浪漫 2016-03-21 12:40 采纳率: 100%
浏览 1518
已采纳

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

 #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;
    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(62) : error C2115: 'function' : incompatible types
C:\Users\20453\Desktop\王俊森\4\4.c(62) : warning C4024: 'DisplayTranscriptOne' : different types for formal and actual parameter 1
C:\Users\20453\Desktop\王俊森\4\4.c(63) : error C2115: 'function' : incompatible types
C:\Users\20453\Desktop\王俊森\4\4.c(63) : warning C4024: 'DisplayTranscriptAll' : different types for formal and actual parameter 1
C:\Users\20453\Desktop\王俊森\4\4.c(64) : error C2115: 'function' : incompatible types
C:\Users\20453\Desktop\王俊森\4\4.c(64) : warning C4024: 'ModifyOne' : different types for formal and actual parameter 1
Error executing cl.exe.

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

  • 写回答

1条回答

  • xSeeker~ 2016-03-21 12:51
    关注

    STUDENT *p1 = MyScore; 类型不一致,MyScore是 STUDENT,p1是STUDENT *,

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)