Crisis du jour: (Linux) Array Error

This is a discussion on Crisis du jour: (Linux) Array Error within the C++ Programming forums, part of the General Programming Boards category; (Sigh....) I finished a program which runs fine on my XP box (Dev C++), but when I compile it under ...

  1. #1
    JKI
    JKI is offline
    Registered User JKI's Avatar
    Join Date
    Sep 2003
    Posts
    19

    Crisis du jour: (Linux) Array Error

    (Sigh....)

    I finished a program which runs fine on my XP box (Dev C++), but when I compile it under Linux (G++), I get:


    In constructor 'Inventory::Inventory()'
    ISO C++ forbids assignment of arrays


    FYI:
    Code:
    struct key                                                   //Private within class
      {
       char invnbr[16];
       int recnbr;
      };
    key *keyptr = new key;
    .....

    Code:
    if (infile.is_open())                                       //Snippet of constructor
     {
      while (! infile.eof())
      {
       infile.read ((char *) &data, sizeof(data));
       keyptr[rrn].invnbr = data.inv_nbr;            //This is the culprit!
       keyptr[rrn].recnbr = rrn;
    
       rrn++;
      }
     }
     infile.close();
    Please tell me there is something short of re-writing my entire code to fix this. My program depends on that array for indexing of a file.
    "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."-Einstein

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Use either memcpy or strcpy( ). You can't copy arrays using the = operator.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    JKI
    JKI is offline
    Registered User JKI's Avatar
    Join Date
    Sep 2003
    Posts
    19
    Originally posted by XSquared
    Use either memcpy or strcpy( ). You can't copy arrays using the = operator.
    Meaning under Linux?

    I'll give it a shot. Just struck me as odd that the program worked fine on my machine and then Linux stuck it's tongue out at me. The main differences I've encountered so far are with libraries and such.

    But, thanks a lot XSquared. I'll post a follow up later today for anyone who is interested.

    :: Jazz
    "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."-Einstein

  4. #4
    JKI
    JKI is offline
    Registered User JKI's Avatar
    Join Date
    Sep 2003
    Posts
    19

    Thumbs up

    strcmp() did the trick.

    (Of course after I compiled and ran it... I found some "other stuff" Linux wasn't too happy with; but that was all my doing... LOL. It never ends! )

    Thanks:: Jazz
    "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."-Einstein

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    I don't think it is Linux, rather the specific compiler.

  6. #6
    JKI
    JKI is offline
    Registered User JKI's Avatar
    Join Date
    Sep 2003
    Posts
    19
    Originally posted by curlious
    I don't think it is Linux, rather the specific compiler.
    Right... poor choice of words on my part. Should've said the compiler.
    "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."-Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 04:27 AM

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