i have problem with array in my c++ program

This is a discussion on i have problem with array in my c++ program within the C++ Programming forums, part of the General Programming Boards category; Hye....i have a problem with my c++ program. i have an error when to compile it....please help me...i didnt know ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    2

    i have problem with array in my c++ program

    Hye....i have a problem with my c++ program. i have an error when to compile it....please help me...i didnt know how to solve it....I got this error when i compile it...

    * '=' cannot convert from 'char' to 'char[50]....it show in setData function...Please help me...



    Code:
    #include <iostream.h>
    
    class Book
    {
    public:
    struct BookData
    {
    char Author[50];
    char ISBN[50];
    char Publisher[50];
    int Year;
    }s_BookData;
    
    public:
    
    
    Book();
    Book(char c_Author, char c_ISBN, char c_Publisher, int c_Year);
    ~Book();
    
    void setData(char c_Author, char c_ISBN, char c_Publisher, int c_Year);
    void getData();
    };
    
    Book::~Book()
    {
    cout<<"The object has been deleted";
    };
    
    Book::Book(char c_Author, char c_ISBN, char c_Publisher, int c_Year)
    {
    setData(c_Author, c_ISBN, c_Publisher, c_Year);
    };
    
    void Book::setData(char c_Author, char c_ISBN, char c_Publisher, int c_Year)
    {
    s_BookData.Author = c_Author;
    s_BookData.ISBN = c_ISBN;
    s_BookData.Publisher = c_Publisher;
    s_BookData.Year = c_Year;
    
    
    };
    
    void Book::getData()
    {
    cout<<s_BookData.Author;
    cout<<s_BookData.ISBN;
    cout<<s_BookData.Publisher;
    cout<<s_BookData.Year;
    };
    
    void main()
    {
    Book obj1("ME", "NOT ME", "NOT ME AGAIN", 16);
    obj1.getData();
    
    };
    Last edited by Salem; 02-09-2011 at 09:36 AM. Reason: Use [code] tags for code.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,602
    Isn't your compiler's explanation enough?!
    Devoted my life to programming...

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,341
    > Book(char c_Author, char c_ISBN, char c_Publisher
    But your members are arrays, not characters.
    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.

  4. #4
    printf("Hello Cboard\n"); codeprada's Avatar
    Join Date
    Jan 2011
    Location
    In a little room at the back of your brain
    Posts
    68
    Code:
    Book(char * c_Author, char * c_ISBN, char * c_Publisher, int c_Year);
    Code:
    Book(char c_Author[], char c_ISBN[], char c_Publisher[], int c_Year);
    you should pass a char array instead of a char.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 17
    Last Post: 09-21-2009, 09:50 PM
  2. simple array of char array problem
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 09-10-2006, 12:04 PM
  3. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

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