473,800 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I am confused and not clear whether the block of code is correct or not

56 New Member
Hi,
Please check whether the following block of code is correct or not.

Expand|Select|Wrap|Line Numbers
  1.       items[index] = 0; // Add an end of list marker
  2.  
  3.       // Add the data to the blob
  4.  
  5.       if (blob_ptr != 0)
  6.       {
  7.          long additional_space = 0;
  8.  
  9.          char** item_ptr = items;
  10.  
  11.          // Calculate the space taken by the new items
  12.  
  13.          while (*item_ptr != 0)
  14.          {
  15.             additional_space += strlen(*item_ptr);
  16.  
  17.             item_ptr++;
  18.          }
  19.  
  20.          // Increase the size of the blob for the new items
  21.  
  22.          blob_ptr = realloc(blob_ptr, blob_size + additional_space + 1);
  23.  
  24.          item_ptr = items;
  25.  
  26.          // Loop through the items and add them to the blob
  27.  
  28.          while (*item_ptr != 0)
  29.          {
  30.             strcat((char*) blob_ptr, *item_ptr);
  31.  
  32.             delete *item_ptr;
  33.  
  34.             item_ptr++;
  35.          }
  36.  
  37.          // Set the new size of the blob
  38.  
  39.          blob_size = blob_size + additional_space;
  40.       }
  41.  
Please help me. Thanks in advance.
Jul 31 '07 #1
2 1185
svlsr2000
181 Recognized Expert New Member
Hi,
Please check whether the following block of code is correct or not.


items[index] = 0; // Add an end of list marker

// Add the data to the blob

if (blob_ptr != 0)
{
long additional_spac e = 0;

char** item_ptr = items;

// Calculate the space taken by the new items

while (*item_ptr != 0)
{
additional_spac e += strlen(*item_pt r);

item_ptr++;
}

// Increase the size of the blob for the new items

blob_ptr = realloc(blob_pt r, blob_size + additional_spac e + 1);

item_ptr = items;

// Loop through the items and add them to the blob

while (*item_ptr != 0)
{
strcat((char*) blob_ptr, *item_ptr);

delete *item_ptr;

item_ptr++;
}

// Set the new size of the blob

blob_size = blob_size + additional_spac e;
}


Please help me. Thanks in advance.
You are using pointer to pointer,
char** item_ptr = items;
This is a good idea when u want to use item by item. Use pointer to array.
Jul 31 '07 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
To the OP: Please use code tags. Read the Reply Guildelines Box to the right of the message window.
Jul 31 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

45
2595
by: Edward K. Ream | last post by:
Hello all, First of all, my present state of mind re pep 318 is one of sheepish confusion. I suspect pep 318 will not affect Leo significantly, but I am most surprised that an apparently controversial feature is being added without a notice, say, in comp.lang.python.announce. I say sheepish, because everyone knows that one should make sure new proposals don't bite you. Still, I would have thought that there were other ways of keeping...
4
5729
by: Florian Brucker | last post by:
Hi! I've got a problem with float & clear. Take this example code: <div style=" width:100px; height:100px; background-color:#FF0000; float:left; margin:10px;"></div> <span style="clear:left;">This is some text</span> In Mozilla 1.6 the span still floats around the image on the left side (as if there wasn't a "clear" option). When I use
6
6333
by: yawnmoth | last post by:
In IE6, setting clear to both in a span tag seems to work, whereas it doesn't seem to work in Firefox. A demonstration can be found here: http://www.frostjedi.com/terra/dev/test3.html Any ideas as to why this might be, and what can be done to make Firefox's rendition of the page the same as IE6's, without using div? Also, I tried replacing nested css stuff (ie. #div3 p, #div3 span) with their own id's (ie. #p and #span) and am now...
0
1397
by: Paul E Collins | last post by:
Hello. I want to display a number of individual blocks of text. Each block has an associated image, which should be displayed on the right and aligned with the top of its block of text, i.e. (use a fixed-width font to view this!) Some short text. +-------+ | | +-------+
10
11129
by: cppdev | last post by:
Hi All! I want to clear the string contents from sensitive information such as passwords, and etc. It's always a case that password will appear as string at some point or another. And i feel uneasy leaving it hanging in memory indefinitely (especially in case when string is Interned). So at leats for the case when string is not interned i propose:
33
3177
by: Lalatendu Das | last post by:
Dear friends, I am getting a problem in the code while interacting with a nested Do-while loop It is skipping a scanf () function which it should not. I have written the whole code below. Please help me in finding why such thing is happening and what the remedy to it is. Kindly bear with my English. int main ()
36
2548
by: utab | last post by:
Dear, I have experince in C( numerical projects, like engineering problems, scientific applications) I have the basic notion of C++ also, I have read Accelerated C++ until Chapter 7, however it seems that it discusses the std and the other part of the language with your own abstractions. Is that better to read a book first on the basic concepts of C++ language (but not the C part) that gives the basics as if the reader is a beginner...
11
1708
by: iTISTIC | last post by:
Developing a new app and am trying to make this my first truly OOP/3-Tier app. I understand the principles of the presentation, business, and data layers. I do, however, have some questions on where certain functionality should be placed and how some things should be implemented. Let's use a simple example such as an application to manage customer records (customer_id, first_name, last_name). I'd have a Customer business object with ID,...
2
3398
by: jhcorey | last post by:
I have the code below that works fine. Note that CellSet does not have a constructor, so I don't have a default way of initializing it. If I try to do something else in the catch block, either ExceptionManager.Publish(ex); or simply commenting out the line, I get a compile error: "Use of unassigned local variable myCellSet". Can anybody explain what is going on? TIA, Jim
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.