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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array of records

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hi, i just can`t seem to get the following code to compile properly.
these are the errors i get...any help would be greatly appreciated :=)
error C2228: left of '.identity' must have class/struct/union type
error C2228: left of '.name' must have class/struct/union type


#include <stdio.h>
#include <string.h>
#define MAX 10

typedef struct {
char name[20];
int identity;
}GOLFER;

void initial_screen(void);
void get_details(GOLFER *ptr);
void print_details(GOLFER player);

void main (void)
{
GOLFER player[MAX];
initial_screen();
get_details(&player[MAX]);
print_details(player[MAX]);

}


void initial_screen(void)
{
printf(&quot;\t*************************************************\n&quot;);
(&quot;\n\t*************************************************\n&quot;);
puts(&quot;\n\t&quot;);
puts(&quot;\tInput Players or (x) to finish input&quot;);
}


void get_details(GOLFER *ptr)
{

int i;
for(i=1;i<=10;i++)
{
printf(&quot;\n\tName : &quot;);
scanf(&quot;%s&quot;, &ptr->name);
printf(&quot;\n\tName : &quot;);
scanf(&quot;%d&quot;, &ptr->identity);
}

}


void print_details(GOLFER player[])
{
int i;
for(i=0;i<=10;i++)
printf(&quot;\n\tNAME\t\t\tID\n&quot;);
printf(&quot;%s %d&quot;,player.name,player.identity);

}
 
Thanks for the reply, i`ve made the necessary changes but it still doesn`t compile. Its says

:-error LNK2001: unresolved external symbol &quot;void __cdecl print_details(struct GOLFER)&quot; (?print_details@@YAXUGOLFER@@@Z)
Debug/Jubilee Cup.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

i`ve no idea:((

#include <stdio.h>
#include <string.h>
#define MAX 10

typedef struct {
char name[20];
int identity;
}GOLFER;

void initial_screen(void);
void get_details(GOLFER *ptr);
void print_details(GOLFER player);

void main (void)
{
GOLFER player[MAX];
initial_screen();
get_details(&player[MAX]);
print_details(player[MAX]);

}


void initial_screen(void)
{
printf(&quot;\t*************************************************\n&quot;);
(&quot;\n\t*************************************************\n&quot;);
puts(&quot;\n\t&quot;);
puts(&quot;\tInput Players or (x) to finish input&quot;);
}


void get_details(GOLFER *ptr)
{

int i;
for(i=0;i<=9;i++,*(ptr+i))
{
printf(&quot;\n\tName : &quot;);
scanf(&quot;%s&quot;, (*ptr).name);
printf(&quot;\n\tName : &quot;);
scanf(&quot;%d&quot;, (*ptr).identity);
}

}


void print_details(GOLFER player[])
{
int i;
for(i=0;i<=9;i++)
printf(&quot;\n\tNAME\t\t\tID\n&quot;);
printf(&quot;%s %d&quot;,player.name,player.identity);

}
 
Hi,

void print_details(GOLFER player)
should be :
void print_details(GOLFER player[]).
(in the header)

Branko


 
i changed it :))

unfortunately its now saying

error C2664: 'print_details' : cannot convert parameter 1 from 'GOLFER' to 'GOLFER []'

 
in main:

print_details(player[MAX]) you pass just one record to the function.
You should pass the whole array (leave the MAX out).

Branko
 
Wondering !?
if your get_details - function is working correctly,
why not use the same format for print_details ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top