C++/help!

Advertisement


Question
i have created:
struct gateType {
      char type[5];
      int input1PinOrder;
      int input2PinOrder;
      int outputPinOrder;
      };
      
struct gateType myGates[8][3];

but in the main program when i write:
myGates[j][i].type="and";
the compiler says: incompatible types in assignment! what should i do??

Answer
Hi,
 You should use the strcpy as follows:

// if char *z contains "and" then
if (sizeof(myGates[j][i].type) >= strlen (z) + 1)
   strcpy (myGates[j][i].type, z);

P.S. Check for any syntax error as I have written the snippet here directly.
Regards,
RaiD

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Dharmender Rai

Expertise

I can answer general and system level C/C++ questions.

Experience

I have 5 years of experience in C++.

©2016 About.com. All rights reserved.