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;
}