//結構體
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)
求大神幫我看看這程序哪錯了,怎麼改,感激不盡
傳進去的實參和函數的形參類型不一樣
#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);
}