473,890 Members | 1,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why delete operator crashes

Hello Folks,
I need to manipulate a list of char strings as follows, but when I want to
delete the pointer created with new at the end, delete operator crashes, any
idea?

char* list[2000];
while(...)
{
list[MyCounter] = new char [Stringlength];
strncpy(list[MyCounter], c_TempFilename, Stringlength);
list[MyCounter][Stringlength] = '\0';
MyCounter++;
}

for (i=0; i<MyCounter;i++ )
{
delete [] list[i];
}

Thanks Everybody in advance.
Feb 23 '06 #1
7 1717
Nemo wrote:
I need to manipulate a list of char strings as follows, but when I want to
delete the pointer created with new at the end, delete operator crashes, any
idea?

char* list[2000];
while(...)
{
list[MyCounter] = new char [Stringlength];
strncpy(list[MyCounter], c_TempFilename, Stringlength);
list[MyCounter][Stringlength] = '\0';
MyCounter++;
}

for (i=0; i<MyCounter;i++ )
{
delete [] list[i];
}
...


You question belongs to C++-related group. Try comp.lang.c++. This is a C group.
There's no "delete operator" in C.

--
Best regards,
Andrey Tarasevich
Feb 23 '06 #2
"Nemo" <nemo@no_email. com> writes:
I need to manipulate a list of char strings as follows, but when I want to
delete the pointer created with new at the end, delete operator crashes, any
idea?


C has no delete operator. You are looking for comp.lang.c++.
--
"The expression isn't unclear *at all* and only an expert could actually
have doubts about it"
--Dan Pop
Feb 23 '06 #3
Nemo wrote:
list[MyCounter] = new char [Stringlength]; delete [] list[i];


I think that's c++.

news:comp.lang. c++

--
pete
Feb 23 '06 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nemo wrote:
Hello Folks,
I need to manipulate a list of char strings as follows, but when I want to
delete the pointer created with new at the end, delete operator crashes, any
idea?

char* list[2000];
while(...)
{
list[MyCounter] = new char [Stringlength];

[snip]

Sorry, but you have the wrong language. Your code is not C (the topic of the
comp.lang.c newsgroup), and appears to be C++ (or perhaps C#)

You've got the wrong room. comp.lang.c++ is down the hall, the 2nd door on the
right (just past the watercooler).

- --
Lew Pitcher
IT Specialist, Corporate Technology Solutions,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)

iD8DBQFD/hZPagVFX4UWr64R AjfhAJ9kr1ikJyy 0HOKQQganQgfqWB mZnwCguDCj
yyjm/beYvTvYtUn4kcL/2bQ=
=3K/p
-----END PGP SIGNATURE-----
Feb 23 '06 #5
OK, OK, Sorry, I did not know new and delete do not exist in C.

"pete" <pf*****@mindsp ring.com> wrote in message
news:43******** ***@mindspring. com...
Nemo wrote:
list[MyCounter] = new char [Stringlength];

delete [] list[i];


I think that's c++.

news:comp.lang. c++

--
pete

Feb 23 '06 #6
Nemo wrote:
Hello Folks,
I need to manipulate a list of char strings as follows, but when I want to
delete the pointer created with new at the end, delete operator crashes, any
idea?
The "new" operator in list[MyCounter] = new char [Stringlength]; and the "delete[]" operator in delete [] list[i]; are syntax errors in C.
You seem to have a question about a different programming language,
probably the one with the newsgroup <news:comp.lang .c++>.
Thanks Everybody in advance.

Don't use bill-collectors' cant unless you are writing dunning letters.
Feb 23 '06 #7
Nemo wrote:
OK, OK, Sorry, I did not know new and delete do not exist in C.


1. Don't top-post. Your replies belong following or interspersed with
properly trimmed quotes.

2. Get a C textbook. K&R2 is often recommended, there are others.

Brian
Feb 23 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2606
by: Dave | last post by:
Hello all, In the code below, I see the following output: base::operator new(size_t, int) base::base() base::~base() base::operator delete(void *) In the case of an exception being thrown during construction, a form of
1
3854
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there are quite a few things that I learned that I did not know before. For example, while I knew that the new and delete operators can be overloaded for classes, I did not know that that the global new and delete operators can also be overloaded. ...
5
2799
by: Ruslan Vorobey | last post by:
Hi All. Does anybody saw any C++ new operator implementations? I need just to know does it use malloc? Especially I interesting about standard C++ libs implementation under AIX 5.1L. Thank you in advance.
4
2682
by: lothar.behrens | last post by:
Hi, I have problems to delare a delete operator in a class and use it to check for valid pointer. Using release() with an additional validation routine from a separate malloc library avoids the double deletion. The first delete will call the destructor and after it the delete operator
13
2064
by: Nemo | last post by:
Hello Folks, I need to manipulate a list of char strings as follows, but when I want to delete the pointer created with new at the end, delete operator crashes, any idea? char* list; while(...) { list = new char ; strncpy(list, c_TempFilename, Stringlength);
3
2490
by: ujjwaltrivedi | last post by:
Can I use any method to allocate /deallocate memory other than new/ delete operators? Actually the problem is while using delete operator in my ".sqc" files the application crashes. It seems the memory location is locked by DB and so it throws an 'unhandled exception'. Following is the code snippet from my application and now i dont wanna touch the basic design. Regards, UvT
5
2119
by: Renato | last post by:
I have an array of pointers to class Shape. I create 4 items and display their values. shapes Shape *shapes; shapes = new Shape (p1); shapes = new Triangle (p1); shapes = new Polygon (p2);
10
2105
by: jeffjohnson_alpha | last post by:
We all know that a new-expression, foo* a = new foo() ; allocates memory for a single foo then calls foo::foo(). And we know that void* p = ::operator new(sizeof(foo)) ; allocates a sizeof(foo)-sized buffer but does NOT call foo::foo().
8
6149
by: Rahul | last post by:
Please read the following code class Test{ public: void * operator new (size_t t) { return malloc(t); } void operator delete (void *p) { free(p); } };
0
9978
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11229
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
10815
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
10923
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
10462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8016
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...
1
4676
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
4271
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3276
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.