GNUstep Crash

This is a discussion on GNUstep Crash within the C Programming forums, part of the General Programming Boards category; Hey I have recently needed to switch to Objective C and am using GNUstep shell to compile C writting on ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    5

    GNUstep Crash

    Hey I have recently needed to switch to Objective C and am using GNUstep shell to compile C writting on my PC. My problem is almost all of my programs crash the moment I enter an imput through scanf. Below is a simple program for a tic tac toe that. I quickly wrote it for myself as the other programs I was running were far to large to debug quickly and as I compile without a problem I feel like it is a GNUstep problem and not a programing problem (unless I am misunderstanding Objective C- C compatability) . If anyone could give me guidance on what the problem could be it would be very helpful.

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    
    
    int main()
        {
            int i;
            int p;
    //10
            startticktack:
            printf ("123\n"); 
        printf ("456\n"); 
        printf ("789\n");
            char board[10] = {69,69,69,69,69,69,69,69,69,69};
            for (i=0 ; i<9 ; i++)
                {
                if (i%2 == 0)
                   {
                   returnx:
                   scanf ("%d", p);
    //20
                   if (board[p]==69)
                        {board[p]=88; // = X
                        printf ("%c ", board[1]); printf ("%c ", board[2]); printf ("%c ", board[3], "\n");
                        printf ("%c ", board[4]); printf ("%c ", board[5]); printf ("%c ", board[6], "\n");
                printf ("%c ", board[7]); printf ("%c ", board[8]); printf ("%c ", board[9], "\n");
                        }
                   else
                        {goto returnx;}
                   }
    //30
                else
                {
                    returny:
                    scanf ("%d", p);
                    if (board[p]==69)
                       {board[p]=89;// = Y
                       printf ("%c ", board[1]); printf ("%c ", board[2]); printf ("%c ", board[3], "\n");
                       printf ("%c ", board[4]); printf ("%c ", board[5]); printf ("%c ", board[6], "\n");
               printf ("%c ", board[7]); printf ("%c ", board[8]); printf ("%c ", board[9], "\n");
                       }
                    else
                        {goto returny;} 
                }
                }
            if (board[1]==board[2] && board[2]==board[3])
               {printf ("Winner on top row!", "\n");}
            if (board[4]==board[5] && board[5]==board[6])
               {printf ("Winner on middle row!", "\n");}
            if (board[7]==board[8] && board[8]==board[9])
               {printf ("Winner on bottom row!", "\n");}
            if (board[1]==board[4] && board[4]==board[7])
               {printf ("Winner on the right!" "\n");}
            if (board[2]==board[5] && board[5]==board[8])
               {printf ("Winner in the middle!" "\n");}        
            if (board[3]==board[6] && board[6]==board[9])
               {printf ("Winner on the left!" "\n");}    
            if (board[1]==board[5] && board[5]==board[9])
               {printf ("Winner on the diagonal!" "\n");}           
            if (board[3]==board[5] && board[5]==board[7])
               {printf ("Winner on the diagonal!" "\n");}  
            printf ("Play again?");
                    char ans;
                    int answer;
                    scanf ("%c", ans);
                    answer=ans;
                    if (answer == 121)
                       {goto startticktack;}
            char response;
            scanf ("%c", response);     
        return 0;                
            }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,514
    Are you running the program from within the GNUstep shell?
    If not, how are you running the program?

    Note: I know very little about GNUstep shell; spent 5 minutes on Google.
    I am guessing it is a Modified MSys shell.

    Edit: You might wish to try a simpler C program to verify it works instead of the one you posted.

    Tim S.
    Last edited by stahta01; 01-02-2012 at 06:06 PM.

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    5
    I am running it within the GNU shell. GNU is the cocoa enviroment for non macs. it is an open source Objective C compiler which I do not believe came from MSys but I could be wrong.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    2,514
    I went with the OS of windows since you stated nothing. I see I still have no idea what OS you are using.

    I suggest trying a different and simpler C program.
    Based on your program; I will guess it is user error mixed with GNUStep being only partly C compatible.

    Tim S.

  5. #5
    Registered User
    Join Date
    Jan 2012
    Posts
    5
    I had tried to simplify the code which then it worked perfectly. The crash always happens around the scanf so if I it to much the problem goes away but that still does not solve my problem. I was wondering if it had anything to do with not releasing the memory as is required in Objective C or maybe the compiler itself is faulty.

    And yes I am using windows 7 atm

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    2,514
    Make sure YOU DO NOT have a folder called mingw in any drive root folder.

    Make sure NO cygwin, MSys, or MinGW folders are in your path other then the ones installed by GNUStep.

    Edit: These are the directions I found for GNUStep http://www.gnustep.org/experience/Windows.html
    Did you follow them?

    Tim S.
    Last edited by stahta01; 01-02-2012 at 06:23 PM.

  7. #7
    Registered User
    Join Date
    Jan 2012
    Posts
    5
    As far as I can tell that is not an issue either.

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    2,514
    I suggest you then ask on a site that supports GNUStep.

    Or wait a few days, to see if anyone else answers.

    Tim S.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Mrpringles View Post
    The crash always happens around the scanf
    I think you'll find scanf() needs a pointer to an int.

    When in doubt... look it up!

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    2,514
    Tater is correct; I was thinking you posted real code that you had working; I should have realized from how bad it looked that is was crap.

    Tim S.

  11. #11
    Registered User
    Join Date
    Jan 2012
    Posts
    5
    Thank you CommonTater I reviewed Objective C and scanf() requires an &point looks like it is working now. Thanks all for your help sped up my conversion drastically as I was stuck on such a simple problem overthinking it. For any others that get this problem syntax should read scanf("%d", &p);

  12. #12
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    There is also turn up the warning level on the compiler, and it will tell you when you screw up printf/scanf calls.
    Code:
    $ gcc -std=c99 -Wall -Wextra bar.c
    bar.c: In function ‘main’:
    bar.c:22: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
    bar.c:26: warning: too many arguments for format
    bar.c:27: warning: too many arguments for format
    bar.c:28: warning: too many arguments for format
    bar.c:37: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
    bar.c:40: warning: too many arguments for format
    bar.c:41: warning: too many arguments for format
    bar.c:42: warning: too many arguments for format
    bar.c:49: warning: too many arguments for format
    bar.c:51: warning: too many arguments for format
    bar.c:53: warning: too many arguments for format
    bar.c:67: warning: format ‘%c’ expects type ‘char *’, but argument 2 has type ‘int’
    bar.c:72: warning: format ‘%c’ expects type ‘char *’, but argument 2 has type ‘int’
    bar.c:22: warning: ‘p’ may be used uninitialized in this function
    bar.c:67: warning: ‘ans’ is used uninitialized in this function
    bar.c:72: warning: ‘response’ is used uninitialized in this function
    It might say warning, but all of them are potential program killers.
    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. Why does it crash?
    By Guti14 in forum C++ Programming
    Replies: 14
    Last Post: 06-11-2010, 05:42 PM
  2. Crash SQL Course
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 01-04-2005, 08:37 AM
  3. Ptr crash.
    By caroundw5h in forum C Programming
    Replies: 12
    Last Post: 08-29-2004, 10:23 AM
  4. Crash after crash!
    By Dual-Catfish in forum C++ Programming
    Replies: 1
    Last Post: 03-31-2002, 08:32 AM
  5. why's it crash?????
    By stevey in forum C Programming
    Replies: 6
    Last Post: 11-08-2001, 12:52 PM

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