Why delete operator crashes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nemo

    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.


  • Andrey Tarasevich

    #2
    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

    Comment

    • Ben Pfaff

      #3
      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

      Comment

      • pete

        #4
        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

        Comment

        • Lew Pitcher

          #5
          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/hZPagVFX4UWr64R AjfhAJ9kr1ikJyy 0HOKQQganQgfqWB mZnwCguDCj
          yyjm/beYvTvYtUn4kcL/2bQ=
          =3K/p
          -----END PGP SIGNATURE-----

          Comment

          • Nemo

            #6
            Re: Why delete operator crashes

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

            "pete" <pfiland@mindsp ring.com> wrote in message
            news:43FE16C4.3 0B3@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]


            Comment

            • Martin Ambuhl

              #7
              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.


              Comment

              • Default User

                #8
                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

                Comment

                Working...