Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:40:41+00:00 2026-06-13T08:40:41+00:00

can anyone help me out with this code.. All i want to do is

  • 0

can anyone help me out with this code..
All i want to do is copy display the character arrays initialized in the main function
am pretty new to cpp and i can’t figure a way out

#include<iostream>
using namespace std;

class base1
{
public:
void setname(char *name);
void setpubl(char *publisher);
void setauth(char *author);
char getname();
char getpubl();
char getauth();
private:
char init_name[50], init_publ[50], init_auth[50];

};

void base1::setname(char *name)
{
int i=0;
while(init_name[i] != '\0')
{
init_name[i]=name[i];
i++;
}
}

void base1::setpubl(char *publisher)
{
int j=0;
while(init_publ[j] != '\0')
{
init_publ[j]=publisher[j];
j++;
}
}

void base1::setauth(char *author)
{
int k=0;
while(init_auth[k] != '\0')
{
init_auth[k]=author[k];
k++;
}

}

const char* base1::getname() const
{
return init_name;
}

const char* base1::getpubl() const
{
return init_publ;
}
const char* base1::getauth() const
{
return init_auth;
}
/*
base1::base1()
{
init_name[0]=0;
init_publ[0]=0;
init_auth[0]=0;
}*/

int main()
{
base1 hello;
char name[]="cpp";
char publisher[]="dreamworks";
char author[]="random";
hello.setname(name);
hello.setpubl(publisher);
hello.setauth(author);
cout<<hello.getname()<<endl;
cout<<hello.getpubl()<<endl;
cout<<hello.getauth()<<endl;
return 0;
}

when i try to compile it it gives me loads of errors. can some one help me out.
i am using g++

errors:

copychar.cpp:49:13: error: prototype for ‘const char* base1::getname() const’ does not match any in class ‘base1’

copychar.cpp:10:6: error: candidate is: char base1::getname()

copychar.cpp:54:13: error: prototype for ‘const char* base1::getpubl() const’ does not match any in class ‘base1’

copychar.cpp:11:6: error: candidate is: char base1::getpubl()

copychar.cpp:58:13: error: prototype for ‘const char* base1::getauth() const’ does not match any in class ‘base1’

copychar.cpp:12:6: error: candidate is: char base1::getauth()

when i am using the following code, only the first character of each string is getting displayed

#include<iostream>
using namespace std;

class base1
{
public:
void setname(char *name);
void setpubl(char *publisher);
void setauth(char *author);
char getname();
char getpubl();
char getauth();
private:
char init_name[50], init_publ[50], init_auth[50];

};

void base1::setname(char *name)
{
int i=0;
while(name[i] != '\0')
{
init_name[i]=name[i];
i++;
}
}

void base1::setpubl(char *publisher)
{
int j=0;
while(publisher[j] != '\0')
{
init_publ[j]=publisher[j];
j++;
}
}

void base1::setauth(char *author)
{
int k=0;
while(author[k] != '\0')
{
init_auth[k]=author[k];
k++;
}

}

char base1::getname()
{
return *init_name;
}

char base1::getpubl()
{
return *init_publ;
}
char base1::getauth()
{
return *init_auth;
}
/*
base1::base1()
{
init_name[0]=0;
init_publ[0]=0;
init_auth[0]=0;
}*/

int main()
{
base1 hello;
char name[]="cpp";
char publisher[]="dreamworks";
char author[]="random";
hello.setname(name);
hello.setpubl(publisher);
hello.setauth(author);
cout<<hello.getname()<<endl;
cout<<hello.getpubl()<<endl;
cout<<hello.getauth()<<endl;
return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:40:43+00:00Added an answer on June 13, 2026 at 8:40 am

    Your loops are wrong, not

    void base1::setpubl(char *publisher)
    {
        int j=0;
        while(init_publ[j] != '\0')
        {
            init_publ[j]=publisher[j];
            j++;
        }
    }
    

    but

    void base1::setpubl(char *publisher)
    {
        int j=0;
        while(publisher[j] != '\0')
        {
            init_publ[j]=publisher[j];
            j++;
        }
        init_publ[j] = '\0'; // ensure destination string is null terminated
    }
    

    Your loop should check for the end of the publisher string that you pass into the function, not for the end of the init_publ string. That doesn’t make much sense since you haven’t given that string a value yet.

    Same for the other loops.

    Also look at this

    char getname();
    

    and this

    const char* base1::getname() const
    

    See the difference? First you say getname is char, then you say it’s const char* and const. You have to be consistent. The second one is correct, replace

    char getname();
    

    with

    const char* getname() const;
    

    Same with getauth and getpubl.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me figure out whats wrong with this piece of xaml code?
Can anyone help me out please? I'm confused. I want to set up my
Can anyone see the problem with this code? When 'out' is returned, it has
Can anyone help out with what im doing wrong here? DEMO HTML <div id=usercurrentccbox>
can anyone help me out with the syntax and example for the target server
I am new in Blackberry. Can anyone help me out for following queries? Which
I am new in Symbian UIQ. So anyone can help me out about following
Can anyone please help me to work out how to achieve the following? I
Anyone that can help me out will be very much appreciated. I seem to
Can anyone help - this is driving me mad. I am calling a mysql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.