2 qq 33271984 qq_33271984 于 2016.03.21 20:40 提问

关于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个回答

bealing
bealing   Rxr 2016.03.21 20:51

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

bealing
bealing 然后那?还是那句话,类型不一致,MyScore是 STUDENT,p1是STUDENT *,
一年多之前 回复
qq_33271984
qq_33271984 这个相当与 STUDENT *p1; p1 = MyScore
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!