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!

Simple code - but not working now ! 3

Status
Not open for further replies.

dickiebird

Programmer
Feb 14, 2002
758
0
0
GB
Given the following code fragments:-

typedef struct
{
char account_code[15];
char agent_code[5];
char description[30];
char deflt_sel_cd[4];
char agnt_spl_acc;
char filler[39];
} B1977_REC;

main()
{
B1977_REC rec;

if(status)
format_agent_code(&rec.agent_code);

etc etc etc
}

void format_agent_code(char *agent)
{
char code1[ AG_LEN + 1 ], code2[ AG_LEN ];
/*
* Check for all spaces
*/
if (strncmp(agent..................
etc etc
}

I get the following error :
"database_access.c", line 6256.27: 1506-280 (W) Function argument assignment between types "unsigned char*" and "unsigned char(*)[5]" is not allowed.

This wasn't ever my code - until now !
Any help or guidance would be most appreciated.

Thanks
Dickie Bird
 
brave compiler!

make a cast.
[tt]
if( status )
format_agent_code( ( unsigned char * ) &rec.agent_code ) ;
[/tt]

hth

norbert
 
Try these:

format_agent_code(rec.agent_code);

or

format_agent_code(&(rec.agent_code));

Please tell us if it does work.

Laurent
 
ooops ... LaurenK is right. the '&' is wrong.

norbert
 
Hi Guys
norbert : The cast to char compiles OK - Thanks

LaurentK :
format_agent_code(rec.agent_code);
COMPILES OK - Thanks

format_agent_code(&(rec.agent_code));
FAILS WITH SAME ERROR AS MINE

Now to run the exe and check the results !!!!!!
Cheers
;-)


Dickie Bird
 
Hi,

Call the function format_agent_code as
format_agent_code(rec.agent_code); //just remove the &, which makes lot of difference in the argument type.

But the error message is something different, it may be there in some other part of the program.

---Maniraja S
 
There's more :
Further down the 7000 lines of the program, there's a
slight change :
format_group_code(rec->agent_code);

The difference between . and -> being what, in this case ?


Dickie Bird
 
rec should be declared as a pointer in that context.
 
So what effect does that have on
format_agent_code(rec->agent_code);
?????/

Dickie Bird
 
It works the same, but rec must be declared as

B1977_REC *rec;

Laurent
 
Thnaks everyone - nearly got to grips with C, then this shows up, and I flounder again !
The later code does indeed have rec declared as a pointer -
- inconsistent or what ? ( perhaps it has to be - I haven't looked that deeply)
So all compiles OK !
Stars all round !
[wavey]

Dickie Bird
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top