Like Tree8Likes

Segmentation fault: I am losing my mind :(

This is a discussion on Segmentation fault: I am losing my mind :( within the C Programming forums, part of the General Programming Boards category; Originally Posted by Median The problem is, when the fscanf finds a SPACE (cell where no one has played it), ...

  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.
    Median likes this.

  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!

Page 3 of 3 FirstFirst 123
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, 03:06 PM
  2. Replies: 6
    Last Post: 03-18-2012, 11: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-27-2002, 12:27 AM
  5. Lost source... losing mind...
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-27-2001, 01:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21