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

  • Home
  • SEARCH
  • 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 6914457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:20:59+00:00 2026-05-27T09:20:59+00:00

So, I’m reading Schildt’s book 3rd edition about C++ and I’m doing all examples,

  • 0

So, I’m reading Schildt’s book 3rd edition about C++ and I’m doing all examples, but I have some PHP background and when I tried some stuff it occurs that it can not be compiled this way.I saw the Schildt’s solution, so I’ll give what I’ve tried to do and how it’s done in the book, what I need to know, is there any way to make it work adjusting my function?

Here’s what I’m trying

class card {
char author[40];
//char book[30];
int count;
public:
    void store(char *auth,int ct);
    void show();
};
void card::store(char *auth,int ct){
    &author = *auth;

    count = ct;
}
int main(){
    card ob1, ob2;
    ob1.store('Tolkin',10);
    ob2.store('Pratchet',3);
    ob1.show();
    ob2.show();
return 0;
}

And here’s the Schildt’s solution:

class card {
char author[40];

int count;
public:
    void store(char *auth,int ct);
    void show();
};
void card::store(char *auth,int ct){
    strcpy(author, auth);

    count = ct;
}
  • 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-05-27T09:21:00+00:00Added an answer on May 27, 2026 at 9:21 am

    I think the basic misunderstanding here is the way that C/C++ handle “char arrays” as strings. The strcpy routine copies the contents of a string, where the = assignment operator (applied to char) copies a single character, or a pointer to the string. &author = *auth will look at the auth pointer, dereference it using *, and take the single char found there, then take the address of (&) your char[] named author, and try to change the address to the char value.

    You could…

    • Use strcpy to copy the contents of the string (but, in new code, don’t use strcpy, use strncpy instead!)
    • Store a pointer to the string provided (char* author in your class would be assigned as author = auth; but then, if auth is free()d or delete[]()ed later, you will have a pointer to memory that no longer contains your string, which is bad)
    • Use a C++ std::string object instead of a C-style char[] for your string, which will behave more like a PHP string would. std::string author could be copied from std::string auth using author = auth.

    String-handling in C++ is a big subject, but you will definitely want to get a good understanding of the differences between “thing” and “pointer-to-thing” types … !

    Also, in C++, you must use "" around strings, and '' around single chars. There is a lot less “magic” in a C/C++ "" string, though; only \x type escape sequences work (for example, there is no "$var" substitution available). In Perl/PHP/Bourne/… you use '' for non-escaped strings and "" for escaped strings; in C++, since char and char[]/std::string are different types, they use the punctuation differently.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.