Deleting char arrays

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

  1. Infiltrator

    Infiltrator

    Joined:
    Oct 15, 2008
    Messages:
    6
    Likes Received:
    0
    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
    Likes Received:
    0
    *bump* *bump*
     
    Infiltrator, Oct 15, 2008
    #2
    1. Advertisements

  3. Infiltrator

    Infiltrator

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

    Infiltrator

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

    Infiltrator

    Joined:
    Oct 15, 2008
    Messages:
    6
    Likes Received:
    0
    ... *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. wwj
    Replies:
    7
    Views:
    841
  2. Bill Reyn
    Replies:
    3
    Views:
    2,785
    Bob Hairgrove
    Jun 22, 2004
  3. wwj
    Replies:
    24
    Views:
    2,992
    Mike Wahler
    Nov 7, 2003
  4. Ben Pfaff
    Replies:
    5
    Views:
    732
    Tristan Miller
    Jan 17, 2004
  5. Steffen Fiksdal

    void*, char*, unsigned char*, signed char*

    Steffen Fiksdal, May 8, 2005, in forum: C Programming
    Replies:
    1
    Views:
    861
    Jack Klein
    May 9, 2005
  6. lovecreatesbeauty
    Replies:
    1
    Views:
    1,442
    Ian Collins
    May 9, 2006
  7. arnuld
    Replies:
    19
    Views:
    943
    Jacek Dziedzic
    Mar 30, 2007
  8. Philipp
    Replies:
    21
    Views:
    1,559
    Philipp
    Jan 20, 2009
Loading...