Thread: Segmentation fault: I am losing my mind :(

  1. #31
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by Median View Post
    The problem is, when the fscanf finds a SPACE (cell where no one has played it), it stops reading and assigns the rest of the line (after the space) to a new line.
    That's how "%s" works. It only reads until the first whitespace.

    One solution is to make sure there are no spaces, i.e. convert spaces to something else before writing and then back after reading.

    Or read one line using fgets() instead of scanf().

    And a sidenote: in SaveGame() you don't need
    Code:
    char *lines[MAXLINES];
    First you don't free the pointers (assuming that LinGameToStr() allocates memory and returns a pointer) and second you don't need an array. You just need one char pointer which you can overwrite each iteration (after freeing it of course).

    Bye, Andreas
    Last edited by AndiPersti; 11-06-2012 at 10:40 AM.

  2. #32
    Registered User
    Join Date
    Sep 2012
    Posts
    43
    OK!

    My game is finally finished, couldn't have done it without your help AndiPertsi!

    Thanks a lot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pipelines - please help, 6 hours and I am losing my mind.
    By Johnny_010 in forum C Programming
    Replies: 4
    Last Post: 04-04-2012, 02:06 PM
  2. Replies: 6
    Last Post: 03-18-2012, 10:11 PM
  3. Array of struct pointers - Losing my mind
    By drucillica in forum C Programming
    Replies: 5
    Last Post: 11-12-2005, 11:50 PM
  4. Don't know if I'm losing my mind...
    By Invincible in forum C++ Programming
    Replies: 19
    Last Post: 05-26-2002, 11:27 PM
  5. Lost source... losing mind...
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-27-2001, 12:31 AM