Why delete operator crashes

Discussion in 'C Programming' started by Nemo, Feb 23, 2006.

  1. Nemo

    Nemo Guest

    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;
    }

    Thanks Everybody in advance.
     
    Nemo, Feb 23, 2006
    #1
    1. Advertising

  2. Nemo

    Ben Pfaff Guest

    "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
     
    Ben Pfaff, Feb 23, 2006
    #2
    1. Advertising

  3. 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;
    > }
    > ...


    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
     
    Andrey Tarasevich, Feb 23, 2006
    #3
  4. Nemo

    Lew Pitcher Guest

    -----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/hZPagVFX4UWr64RAjfhAJ9kr1ikJyy0HOKQQganQgfqWBmZnwCguDCj
    yyjm/beYvTvYtUn4kcL/2bQ=
    =3K/p
    -----END PGP SIGNATURE-----
     
    Lew Pitcher, Feb 23, 2006
    #4
  5. Nemo

    pete Guest

    Nemo wrote:

    > list[MyCounter] = new char [Stringlength];


    > delete [] list;


    I think that's c++.

    news:comp.lang.c++

    --
    pete
     
    pete, Feb 23, 2006
    #5
  6. Nemo

    Nemo Guest

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

    "pete" <> wrote in message
    news:...
    > Nemo wrote:
    >
    > > list[MyCounter] = new char [Stringlength];

    >
    > > delete [] list;

    >
    > I think that's c++.
    >
    > news:comp.lang.c++
    >
    > --
    > pete
     
    Nemo, Feb 23, 2006
    #6
  7. 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;

    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.
     
    Martin Ambuhl, Feb 23, 2006
    #7
  8. Nemo

    Default User Guest

    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
     
    Default User, Feb 23, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jef Driesen
    Replies:
    1
    Views:
    509
    Gernot Frisch
    Jan 19, 2005
  2. Amy
    Replies:
    13
    Views:
    6,024
    Kurt Stutsman
    Feb 23, 2005
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,030
    Smokey Grindel
    Dec 2, 2006
  4. Nemo
    Replies:
    13
    Views:
    483
  5. tom
    Replies:
    5
    Views:
    413
Loading...

Share This Page