Thread: Segmentation Fault With pointer to pointer strcpy

  1. #1
    Registered User touchy's Avatar
    Join Date
    Mar 2011
    Posts
    2

    Segmentation Fault With pointer to pointer strcpy

    Perhaps I am just mental, but when I try to run [C++] Segmentation Fault - Pastebin.com , I get seg faults whenever I try to call the line 219 in the function getFileName. Did I do this correctly? I hope this is the correct place to post, and if not, I apologize.

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    You use of an uninitialised char * pointer on line 207 is what is causing a segmentation fault.

    You should not be using functions such as strcat or strcpy since this is C++. You should just use regular std::strings for the whole lot, and that includes for your member variables. You have several memory leaks because of not using std::strings.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User touchy's Avatar
    Join Date
    Mar 2011
    Posts
    2
    Quote Originally Posted by iMalc View Post
    You use of an uninitialised char * pointer on line 207 is what is causing a segmentation fault.

    You should not be using functions such as strcat or strcpy since this is C++. You should just use regular std::strings for the whole lot, and that includes for your member variables. You have several memory leaks because of not using std::strings.
    Thanks for the suggestion. After I removed all of the char arrays and did some minor changes, it's working great.
    [C++] fix'd - Pastebin.com

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Yep that looks great now, well done!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  2. segmentation fault... first time with unix...
    By theMethod in forum C Programming
    Replies: 16
    Last Post: 09-30-2008, 02:01 AM
  3. Segmentation Fault?
    By magda3227 in forum C Programming
    Replies: 10
    Last Post: 07-10-2008, 07:26 AM
  4. Re: Segmentation fault
    By turkish_van in forum C Programming
    Replies: 8
    Last Post: 01-20-2007, 05:50 PM
  5. Segmentation fault with a file pointer?
    By Matt13 in forum C Programming
    Replies: 14
    Last Post: 07-31-2004, 05:53 AM