Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello Guys I get the following

Status
Not open for further replies.

OOzy

Programmer
Jul 24, 2000
135
SA
Hello Guys

I get the following error when I use the Unix cc compiler

------------------------------
cc-1164 cc: WARNING File = struct.c, Line = 39
Argument of type "struct Student (*)[5]" is incompatible with parameter of
type "struct Student *".

FindMax(&list, 5);
------------------------------

and I get the following errors if I use gcc or VC++ compilers.

------------------------------
warning C4047: 'function' : 'struct Student *' differs in levels of indirection from 'struct Student (*)[5]'
warning C4024: 'FindMax' : different types for formal and actual parameter 1
------------------------------

Can anybody tell me how can I fix them? My program is listed below.

/* Struct Assignment */


#include <stdio.h>

int i;
struct Student
{
int Score;
char Name[10];
};


void FindMax(struct Student *myStruct, int index);


void main()
{


struct Student list[5] =
{
{90,&quot;Mike&quot;},
{50,&quot;Don&quot;},
{89,&quot;Tom&quot;},
{70,&quot;Jeff&quot;},
{100,&quot;Ron&quot;}
};

printf(&quot;Name\t\tScore\n&quot;);
printf(&quot;----\t\t-----\n&quot;);
for (i = 0; i < 5; i++)
{
printf(&quot;%s&quot;, list.Name);
printf(&quot;\t\t%d\n&quot;, list.Score);
}


FindMax(&list, 5);

}


void FindMax(struct Student *myStruct, int index)
{
int HighScore, i;
int HighStudent;
HighScore=0;


for (i=0; i<index; i++)
{

if (((myStruct+i)->Score) > HighScore)
{
HighScore = (myStruct+i)->Score;
HighStudent = i;
}
}

printf(&quot;The Student that has the highest score is: &quot;);
printf(&quot;%s \n&quot;, (myStruct+HighStudent)->Name);
printf(&quot;The highest score is: %d \n&quot;,HighScore);




}

 
Ii told you before that you have to pass parameters like this:

FindMax(list,index);
because list itself is a pointer to the first structure, so if you tried to put reference there it would be pointer to a pointer.
In your function signature you could use this list and index would be the index of the structure you wanted to pass. Best Regards,

aphrodita@mail.krovatka.ru {uiuc rules}
 
You are kidding me. Wow. It worked. That was easy. Thank you so much
 
plz. check the earlier querry I have posted the answer to it there.

SwapSawe.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top