麻烦帮我看下,我调试了好久就是得不到结果……
这是我书上的一个机试题,题目要求是通过形参指针传回主函数的一个最高分(只有一个最高分)。不知道为什么,有错误提示,但就是看不懂,以下就是,实在是逼的我没话说……
#include<stdio.h>
#include<string.h>
#define N 10
typedef struct
{
char name[10];
int s;
}STU;
void fun(STU a[],STU *m)
{
m=a;
for(int i=1;i<N;i++)
if(strcmp(a[i].s,*m.s)>0)
m=&a[i];
}
void main()
{
STU a[N]={{"A01",81},{"A02",89},{"A03",66},{"A04",87},{"A05",77},{"A06",90},{"A07",79},{"A08",61},{"A09",80},{"A10",71}},m;
int i;
fun(a,&m);
printf("****the result****\n");
printf("the top %s,%d\n",m.num,m.s);
}
错误提示如下:
--------------------Configuration: 3_3 - Win32 Debug--------------------
Compiling...
3_3.cpp
F:\C++文档\3_3\3_3.cpp(13) : error C2228: left of '.s' must have class/struct/union type
F:\C++文档\3_3\3_3.cpp(13) : error C2664: 'strcmp' : cannot convert parameter 1 from 'int' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
F:\C++文档\3_3\3_3.cpp(22) : error C2039: 'num' : is not a member of 'STU'
F:\C++文档\3_3\3_3.cpp(5) : see declaration of 'STU'