snake game segmentation fault

This is a discussion on snake game segmentation fault within the Game Programming forums, part of the General Programming Boards category; Edit: Removed my post because of a hateful poster below. come on! beat my head with 2x4????? Does he even ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    2

    snake game segmentation fault

    Edit: Removed my post because of a hateful poster below.
    come on! beat my head with 2x4????? Does he even know what programming is and what this forum is for? And why people use these boards? BECAUSE THEY NEED "HELP" WITH THEIR CODE and becasue they are STILL LEARNING. The below poster should be banned for yelling at people because they dont post their "entire" code//go figure why the poster wants to "look" at all other person's full code. This cboard is not useful for an average programmer at all :X
    Last edited by dingdong; 04-30-2011 at 03:18 PM. Reason: wow! what a rude little person we got here. This below poster should be banned for using crude language.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    > FILE *s_game;
    If you're not getting any compiler warnings, then get a better compiler.
    If you're getting warnings, but ignoring them, beat yourself about the head with a 2x4

    > game *g_game=malloc(sizeof(game));
    > if (g_game= fopen(file_name, "r") == NULL)

    ...

    > fclose(g_game);
    > return g_game;

    You're seriously screwed up over s_game / g_game


    > if (g_game= fopen(file_name, "r") == NULL)
    And for this, you need to learn about operator precedence.
    Normally, you write this here - note the extra ( )
    if ( (g_game= fopen(file_name, "r")) == NULL)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    2
    oops that was not the mistake when i typed the code here, i made typos..but im still getting segmentation fault.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    Look, unless you're going to copy/paste DIRECTLY from your IDE/text editor, there isn't a lot of point bothering to post at all.

    Likewise, just saying "it doesn't work" adds 0% information as well.

    How To Ask Questions The Smart Way
    Not some CSI "Well the bug was about 5'9, about 170lb and was last seen wearing jeans and a dark coloured jacket"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About SnaKE game..
    By ozumsafa in forum C Programming
    Replies: 3
    Last Post: 10-19-2007, 06:46 PM
  2. Hangman Game - Rewrite (Segmentation Fault?)
    By tigrfire in forum C Programming
    Replies: 4
    Last Post: 11-29-2005, 07:56 PM
  3. Snake Attack! my game
    By SmashBro in forum Game Programming
    Replies: 8
    Last Post: 12-01-2002, 05:55 PM
  4. My Snake Game
    By ()Q() in forum Game Programming
    Replies: 2
    Last Post: 07-23-2002, 04:03 PM
  5. game (snake)
    By nps in forum C Programming
    Replies: 1
    Last Post: 10-09-2001, 11:37 PM

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