lvalue error trying to copy between structures

This is a discussion on lvalue error trying to copy between structures within the C Programming forums, part of the General Programming Boards category; I am trying to copy data between two structures, i.e. from record read in to record to be written out. ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    20

    lvalue error trying to copy between structures

    I am trying to copy data between two structures, i.e. from record read in to record to be written out.
    This is in Microsoft C (ver6).

    I have them declared like this
    Code:
    struct GLD0DATA
       {
       char GlSt	;       /* 0    */
       char	Filler1 [20];	/* 1    */
       char GlAcCC  [2];    /* 21   */
       char GlAcCX  [1];    /* 23   */
    <snip>
       char GlMatDt [6];    /* 442  */
       char GlFill5 [1416]; /* 448  */
       char GlDrac  [7];    /* 1864 */
       char GlCrac	[7];    /* 1871 */
       char GlFill6 [170];  /* 1878  fill out till end  */
       };                   /* 2048 */
    
    struct ICRSEX1A
       {
       char ICAcCC  [2];  
       char ICAcCX  [1];  
       char ICAcMM  [2]; 
       char ICAcno  [6];
       char ICAcSS  [2];	
       char ICCrInt [9];    
       char ICDrInt [9];    
       char ICMatDt [6];    
       };      
    
    char WKAcCC  [2];  
    char WKAcCX  [1];  
    char WKAcMM  [2]; 
    char WKAcno  [6];
    char WKAcSS  [2];	
    char WKCrInt [9];    
    char WKDrInt [9];    
    char WKMatDt [6];    
    
    int             IN_BUF_LEN;
    int             OUT_BUF_LEN;
    struct GLD0DATA REC_BUF,  *pi;             /*  initially I did not use pointers   */
    struct ICRSEX1A OUT_BUF,  *po;             /*  with pointers still get same error */   
    char            IN_POS_BLK[128];
    char            OUT_POS_BLK[128];
    char            IN_KEY_BUF[2];
    char            OUT_KEY_BUF[2];
    char            FIL_NAME[60]= "";
    char            OUT_NAME[60]="";
    
    main ()
    {
       pi = &REC_BUF;
       po = &OUT_BUF;
    First I tried directly from structure to structure, then put in intermediary work variables
    (as shown)

    Code:
    	    if (strncmp(str1,"     ",5) != 0)
    	    {
    		WKAcCC  =  pi->GlAcCC;
    		WKAcCX  =  pi->GlAcCX;
    		WKAcMM  =  pi->GlAcMM;
    		WKAcno  =  pi->GlAcno;
    		WKAcSS  =  pi->GlAcSS;
    		WKCrInt =  pi->GlCrInt;
    		WKDrInt =  pi->GlDrInt;
    		WKMatDt =  pi->GlMatDt;
    
    
    		po->ICAcCC  =  WKAcCC;
    		po->ICAcCX  =  WKAcCX;
    		po->ICAcMM  =  WKAcMM;
    		po->ICAcno  =  WKAcno;
    		po->ICAcSS  =  WKAcSS;
    		po->ICCrInt =  WKCrInt;
    		po->ICDrInt =  WKDrInt;
    		po->ICMatDt =  WKMatDt;
    but still get same error when compiling
    "error C2106: '=' : left operand must be lvalue"

    Any help appreciated!

    Thanks,
    Bob
    Last edited by emanresu; 11-16-2006 at 05:35 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    Char arrays need to be copied with
    - strcpy - if it's a short printable string with a \0
    - strncpy - it it's a longer printable string, possibly without a \0
    - memcpy - if it's arbitrary binary data
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    20
    Thanks for the v.quick reply! I'll try it out.

    Wish I was a God and not a hacker...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  2. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  3. dynamic memory alloccation & returning objects
    By haditya in forum C++ Programming
    Replies: 8
    Last Post: 04-21-2005, 11:55 PM
  4. Copy Constructor Help
    By Jubba in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 10:15 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21