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!

assigning one char array to another....... 2

Status
Not open for further replies.

johnfdutcher

Programmer
Dec 16, 2003
12
0
0
US
Given a structure as below I tried to assign char array members of another structure to those in this one (as shown); the compiler returns:

"request for member 'seq_tray' in something not a structure or a union"
(repeated for each member assignment in the code below replacing 'seq_tray' with the appropriate member name on the 'left' of the assign attempt). I knew it couldn't be that simple....but thought arrays could be assigned to each other if of the same size ????

****** structure to be filled *******
struct item_struct {
int seq_tray;
char seq_lname[15];
char seq_fname[15];
char seq_minit;
char seq_recnbr[3];
char seq_regnbr[4];
};
struct item_struct table_item[300];

******** code lines ***************
table_item.seq_tray[cur_tbl] = found;
table_item.seq_lname[cur_tbl] = rec.last_name;
table_item.seq_fname[cur_tbl] = rec.first_name;
table_item.seq_minit[cur_tbl] = rec.mid_initial;
table_item.seq_recnbr[cur_tbl] = rec.recnbr;
table_item.seq_regnbr[cur_tbl] = rec.regnbr;

found is an integer; all other rec.xxxx 'members' are character arrays or single characters.
 
Arrays cannot be assigned in C using the '=' operator.

use [red]strcpy[/red] or [red]memmove[/red] instead.

________________________________________
Roger J Coult; Grimsby, UK
In the game of life the dice have an odd number of sides.
 
> table_item.seq_tray[cur_tbl] = found;
It's the wrong order
[tt]table_item[cur_tbl].seq_tray = found;
[/tt]

> table_item.seq_lname[cur_tbl] = rec.last_name;
You can't assign an array, use strcpy
[tt]strcpy(table_item[cur_tbl].seq_lname, rec.last_name );
[/tt]

--
 
Needs to be pointers.
struct item_struct {
int seq_tray;
char *seq_lname;
char *seq_fname;
char *seq_minit;
char *seq_recnbr;
char *seq_regnbr;
};
struct item_struct table_item[300];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top