Connecting Tech Pros Worldwide Forums | Help | Site Map

Why delete operator crashes

Nemo
Guest
 
Posts: n/a
#1: Feb 23 '06
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.



Andrey Tarasevich
Guest
 
Posts: n/a
#2: Feb 23 '06

re: Why delete operator crashes


Nemo wrote:[color=blue]
> 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];
> }
> ...[/color]

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
Ben Pfaff
Guest
 
Posts: n/a
#3: Feb 23 '06

re: Why delete operator crashes


"Nemo" <nemo@no_email.com> writes:
[color=blue]
> 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?[/color]

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
pete
Guest
 
Posts: n/a
#4: Feb 23 '06

re: Why delete operator crashes


Nemo wrote:
[color=blue]
> list[MyCounter] = new char [Stringlength];[/color]
[color=blue]
> delete [] list[i];[/color]

I think that's c++.

news:comp.lang.c++

--
pete
Lew Pitcher
Guest
 
Posts: n/a
#5: Feb 23 '06

re: Why delete operator crashes


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nemo wrote:[color=blue]
> 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];[/color]
[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-----
Nemo
Guest
 
Posts: n/a
#6: Feb 23 '06

re: Why delete operator crashes


OK, OK, Sorry, I did not know new and delete do not exist in C.

"pete" <pfiland@mindspring.com> wrote in message
news:43FE16C4.30B3@mindspring.com...[color=blue]
> Nemo wrote:
>[color=green]
> > list[MyCounter] = new char [Stringlength];[/color]
>[color=green]
> > delete [] list[i];[/color]
>
> I think that's c++.
>
> news:comp.lang.c++
>
> --
> pete[/color]


Martin Ambuhl
Guest
 
Posts: n/a
#7: Feb 23 '06

re: Why delete operator crashes


Nemo wrote:[color=blue]
> 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?[/color]

The "new" operator in[color=blue]
> list[MyCounter] = new char [Stringlength];[/color]
and the "delete[]" operator in[color=blue]
> delete [] list[i];[/color]
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++>.
[color=blue]
> Thanks Everybody in advance.[/color]
Don't use bill-collectors' cant unless you are writing dunning letters.


Default User
Guest
 
Posts: n/a
#8: Feb 23 '06

re: Why delete operator crashes


Nemo wrote:
[color=blue]
> OK, OK, Sorry, I did not know new and delete do not exist in C.[/color]

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
Closed Thread


Similar C / C++ bytes