473,785 Members | 2,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

which delete line is correct?

56 New Member
I have a similar kind of code as below. But I could not guess how to delete. Please help me.
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. int main()
  5. {
  6.         char* items[5];
  7.         int i;
  8.         for(i=0;i<5;i++)
  9.         {
  10.                 char* temp = new char[11];
  11.                 strcpy(temp,"AB CD EFGH");
  12.                 items[i] = temp;
  13.                 printf("items is:%u\n",&items[i]);
  14.                 printf("strlen of items is:%d\n",strlen(items[i]));
  15.         }
  16.         items[5] = 0;
  17.         char** item_ptr = items;
  18.         while (*item_ptr != 0)
  19.         {
  20.                 printf("item_ptr is:%u\n",*item_ptr);
  21.                 delete *item_ptr;  //whether this is correct?
  22.                 //delete []*item_ptr;      or this is correct?
  23.                 item_ptr++;
  24.         }
  25.         return 0;
  26. }
  27.  
Please let me know how to use the delete here. Thanks in advance.
Aug 8 '07 #1
1 1523
Darryl
86 New Member
The second one since you are deleting the result from char* temp = new char[11];

use delete[ ] with new [ ]
and delete with new

however, you didn't need to make char** item_ptr = items;

You could just use items directly
Expand|Select|Wrap|Line Numbers
  1.  for(i=0;i<5;i++)
  2. {
  3.      delete[] items[i];
  4. }
Aug 8 '07 #2

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

Similar topics

19
3701
by: deko | last post by:
I'm kind of lost on this one - I need to modify 2 files based on user input: $data_array = file($data_file); $counter_array = file($counter_file); // There is a line-for-line relationship between the data and counter files //for example, if the 3rd line in the counter file is deleted, //so also must the 3rd line of the data file be deleted. // Each line of the data_file has 4 items: //date|ip_address|user_id|url for ( $i=0; $i <...
4
2620
by: Scotter | last post by:
Hi folx - Here is the code I'm trying (but it errors out with "Item cannot be found in the collection corresponding to the requested name or ordinal."): objTable.Columns(s_name_field_to_delete).delete AND SAME ERROR WITH: objTable.Columns.delete s_name_field_to_delete AND SAME ERROR WITH: set objColumn = objTable.Columns(s_name_field_to_delete)
5
336
by: Jona Schuman | last post by:
Hi, there was a memory leak in a programming assignment that I'm working on. The problem seems to have been a syntax error in a delete statment: delete V1, V2; //where V1 & V2 are pointers to vectors Running a trace revealed that only V1 was being deleted, and replacing the line as follows fixed the leak: delete V1; delete V2;
9
2936
by: Venn Syii | last post by:
I have the following line of code: if (MyData) { delete MyData; MyData= NULL; } Below is MyData: SomeDataStructure *MyData;
3
4653
by: silver360 | last post by:
Hello, I'm trying to create a basic Heap manager and i have some question about new/delete overloading. The following code give me this output : >> $./heap >> registered : 0x804d098 >> 0x804d008 _Delete unknown block >> registered : 0x804d138 >> 0x804d008 _Delete unknown block >> 0x804d098 _Delete ok
6
41965
by: tomtown.net | last post by:
Hello I'm trying to get a single line removed from a text file using a search pattern (pretty simple: if line contains "NODE1") -> remove line). To achieve this I's like to operate with only the original file and no temp file since the file is 1. on a network resource 2. pretty big 3. accessed by plenty of clients. Copying the file or reading everything into an array and then writing it back using the StreamWriter would lock the file...
6
278
by: jafarikia | last post by:
Hi, I am using pointer in my program. I write them like: *DIST=new int ; and when I want to make the memory free, I write: delete DIST; just before the "return 0". I don't know if the way that I am doing is correct or not because I
20
4651
by: Martin Jørgensen | last post by:
Hi, I'm reading a number of double values from a file. It's a 2D-array: 1 2 3 4 5 6 7 ------------- 1 3.2 2 0 2.1 3 9.3 4
24
7564
by: biganthony via AccessMonster.com | last post by:
Hi, I have the following code to select a folder and then delete it. I keep getting a Path/File error on the line that deletes the actual folder. The line before that line deletes the files in the folder but I get the error message when the procedure attempts to delete the folder selected in the BrowseforFolderbyPath function. How can I get it to delete the folder that the user has selected in the Browse for Folder dialog?
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
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
10091
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
8972
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
7499
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
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.