Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Visual C++ 2013
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2013 by Ivor Horton; ISBN: 978-1-118-84571-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2013 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 17th, 2014, 07:45 AM
Authorized User
 
Join Date: Jan 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default I don't understant Exercise 2 ch7

Hi!
I have written my own code for exercise 2 chapter7.
I then compare it with Soln7_02.cpp file from the downloaded code.

I then used only Soln7_02.cpp file cause my code was not correct!
I don't understand following lines:

Code:
   char* s{ "Hello World!" };
   a.sptr = new char[strlen(s)+1];
   strcpy_s(a.sptr, strlen(s)+1, s);
As it seems there is a pointer to char s allocated with address of "Hello World!"
Then pointer of object a is allocated a memory space of 13 bytes (char)
And then there is a copy of string s which is 12 characters long to the sptr
which is 13 characters long.
Why the destination is made 13 characters long? Is it to accommodate the null terminating character?

Answer me this for now...

Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
ch7 sub menu don't display liwenz BOOK: Beginning ASP.NET 4 : in C# and VB 3 September 2nd, 2013 02:34 PM
Navigation - ch7. wingri BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 April 8th, 2008 08:29 AM
Parse error: CH7 p198 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 16th, 2004 08:07 PM
CH7 - import package kizmit JSP Basics 4 June 16th, 2004 08:00 AM
Doing ch7 would u help me out? mara JSP Basics 1 November 18th, 2003 09:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.