Troubles with char and structs

This is a discussion on Troubles with char and structs within the C++ Programming forums, part of the General Programming Boards category; hi, I could do with some assistance with the following a .h class file. Code: struct aStruct { char X[20], ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    5

    Troubles with char and structs

    hi, I could do with some assistance with the following
    a .h class file.
    Code:
    struct aStruct
    {
    	char X[20], Z[20];
    };
    
    class Example
    {
    	aStruct aStruct[5]; 
    public:
            void AddaStruct(char X[20], char Z[20]);
    };
    
    void Example::AddaStruct(char X[20]. char Z[20])
    {
            aStruct[1].X[20] = X[20];
    	aStruct[1].Z[20] = Z[20];
    }
    then I have the following .cpp minus the header files.

    Code:
    int main(void)
    {
    	Example Example;
            char X[20] = "Test";
    	char Z[20] = "Test 1";
    	Example.AddaStruct(X, Y);
    //then a get comand that shows aStruct[1]'s X and z to screen
    }
    this doesn't show the "Test" which I put in.
    any ideas as to what I done wrong or a better method?
    thanks.

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    5
    thanks for the quick reply, but that seems to have had no effect, I still have the same output

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    5
    Code:
    struct aStruct
    {
    	char X[20], Z[20];
    };
    
    class Example
    {
    	aStruct aStruct[5]; 
    public:
            void AddaStruct(char X[20], char Z[20]);
    	char GetX();
    	char GetY();
    
    };
    
    void Example::AddaStruct(char X[20]. char Z[20])
    {
            aStruct[1].X[20] = X[20];
    	aStruct[1].Z[20] = Z[20];
    }
    
    char Tape::GetX()
    {
    	return aStruct[1].X[20];
    }
    
    char Tape::GetY()
    {
    	return aStruct[1].Y[20];
    }
    Code:
    int main(void)
    {
    	Example Example;
            char X[20] = "Test";
    	char Z[20] = "Test 1";
    	Example.AddaStruct(X, Y);
            cout << "X is : " << Tape.getX() << "Y is : " << Tape.getY();
    
    	
    }
    That any better?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. display copied data into structs
    By bazzano in forum C Programming
    Replies: 5
    Last Post: 05-02-2006, 03:12 PM
  2. accessing array of structs values
    By WaterNut in forum C++ Programming
    Replies: 12
    Last Post: 07-08-2004, 09:47 PM
  3. Replies: 3
    Last Post: 04-19-2004, 07:42 PM
  4. Segmentation Fault printing an array of structs
    By ccoder01 in forum C Programming
    Replies: 1
    Last Post: 04-17-2004, 08:03 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM

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