Thread: Problem with new :/

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    27

    Problem with new :/

    Code:
    char* file_location = new char;
          strncat (file_location, filename, strlen(filename) - strlen(basename(filename)));
          strcat (file_location, "../conf/sync.conf");
          file = new char;
          strcpy (file, file_location);
    Simply enough, i takes file_location, copies filename into it minus the filename, and then adds "../conf/sync.conf"

    (filename is a string to the absolute path of the program being ran)

    But, when the "file = new char;" is called, it cuts down the string file_location a lot, making the file sync.conf unopenable o_0;

    Why is new on a variable killing a different one? o_0
    Can I only have one new at a time.. or.. ? x_X

    Thanks...

    Funny, doing this in the malloc way works fine =(
    Last edited by Zarkhalar; 08-03-2004 at 08:14 PM. Reason: update

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM