问题描述
- 关于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:Users20453Desktop王俊森44.c(30) : error C2115: 'initializing' : incompatible types
C:Users20453Desktop王俊森44.c(64) : error C2115: 'function' : incompatible types
C:Users20453Desktop王俊森44.c(64) : warning C4024: 'DisplayTranscriptOne' : different types for formal and actual parameter 1
C:Users20453Desktop王俊森44.c(65) : error C2115: 'function' : incompatible types
C:Users20453Desktop王俊森44.c(65) : warning C4024: 'DisplayTranscriptAll' : different types for formal and actual parameter 1
C:Users20453Desktop王俊森44.c(66) : error C2115: 'function' : incompatible types
C:Users20453Desktop王俊森44.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)
求大神帮我看看这程序哪错了,怎么改,感激不尽
解决方案
传进去的实参和函数的形参类型不一样
#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);}
解决方案三:
#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 %.2fn"" (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 %.2fn"" (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);}
好了我改好了 运行上也没错误了