Deleting char arrays

Discussion in 'C Programming' started by Infiltrator, Oct 15, 2008.

  1. Infiltrator

    Infiltrator

    Joined:
    Oct 15, 2008
    Messages:
    6
    Can somebody please tell me what I'm doing wrong here? :/
    If I remove the "rename = 0;" line, the delete[] doesn't cause a crash, but then how do I null terminate it? :/

    Code (Text):
    unsigned long long int getFileSize(string file)
    {
        int length = file.length();
        char *rename = new char[length];
        int i = 0;

        while(i < length)
        {
            rename[i] = file.at(i);
            i++;
        }
        rename[i] = 0;

        unsigned long long int result = getFileSize(rename);
        delete[] rename;           //Stack heap corruption here
        return result;
    }
     
    Infiltrator, Oct 15, 2008
    #1
    1. Advertisements

  2. Infiltrator

    Infiltrator

    Joined:
    Oct 15, 2008
    Messages:
    6
    *bump* *bump*
     
    Infiltrator, Oct 15, 2008
    #2
    1. Advertisements

  3. Infiltrator

    Infiltrator

    Joined:
    Oct 15, 2008
    Messages:
    6
    *bump* Anyone there?
     
    Infiltrator, Oct 15, 2008
    #3
  4. Infiltrator

    Infiltrator

    Joined:
    Oct 15, 2008
    Messages:
    6
    Um? Is there a reason nobody's replying? :/
     
    Infiltrator, Oct 16, 2008
    #4
  5. Infiltrator

    Infiltrator

    Joined:
    Oct 15, 2008
    Messages:
    6
    ... *bump*
     
    Infiltrator, Oct 18, 2008
    #5
    1. Advertisements

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. Bill Reyn
    Replies:
    3
    Views:
    2,463
    Bob Hairgrove
    Jun 22, 2004
  2. lovecreatesbeauty
    Replies:
    1
    Views:
    1,259
    Ian Collins
    May 9, 2006
  3. Harry Barker
    Replies:
    2
    Views:
    592
    Alf P. Steinbach
    Apr 19, 2006
  4. Philipp
    Replies:
    21
    Views:
    1,275
    Philipp
    Jan 20, 2009
  5. crea
    Replies:
    2
    Views:
    506
    Nobody
    Dec 28, 2012
Loading...

Share This Page