qq_33271984
良辰好景虚设w
2016-03-21 12:40

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

  • struct
  • c
  • typedef
  • 指针
  • 结构
 #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条回答