1

I ended up doing like this,

struct init
{
    CHAR Name[65];
};

void main()
{
    init i;

    char* _Name = "Name";

    int _int = 0;

    while (_Name[_int] != NULL)
    {
        i.Name[_int] = _Name[_int];
        _int++;
    }
}
Skurmedel
  • 21,515
  • 5
  • 53
  • 66
cpx
  • 17,009
  • 20
  • 87
  • 142

3 Answers3

5

Give your structure a constructor:

struct init
{
  char Name[65];
  init( const char * s ) {
     strcpy( Name, s );
  }
};

Now you can say:

init it( "fred" );

Even without a constructor, you can initialise it:

init it = { "fred" };
2

In C++, a struct can have a constructor, just like a class. Move the initialization code to the constructor. Also consider using a std::string instead of the char array.

struct init
{
    std::string name;

    init (const std::string &n) : name (n)
    {
    }
};
Vijay Mathew
  • 26,737
  • 4
  • 62
  • 93
2

You could also use strcpy() to copy your string data into the char array.

strcpy(i.Name, "Name");
xan
  • 7,440
  • 8
  • 43
  • 65