472,342 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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 1620
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/hZPagVFX4UWr64RAjfhAJ9kr1ikJyy0HOKQQganQgfqWBmZnwC guDCj
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*****@mindspring.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
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...
1
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...
5
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...
4
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...
13
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...
3
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...
5
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);...
10
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...
8
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 ...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.