samedi 17 décembre 2016

Operator == doesn't work in C

I'm getting a weird error while writing my program in C.

Here is my code:

#include <stdio.h>
#include <stdlib.h>
#include "defs.h"
int main (int argc, char* argv[])
{
 int boardSize = atoi(argv[2]);

 int generations = atoi(argv[4]);

int gamesort = atoi(argv[1]);
printf("2 is %d 1 is %d 4 is %d name of file is %s \n",boardSize,gamesort,generations,argv[3]);

    if (1==1)
    {
    printf("yes");
        ZeroPlayersGame(boardSize, generations,argv[3]);
    }
    else//(gamesort==2)
    {
        TwoPlayersGame(boardSize, generations,argv[3]);
    }
    return 0;
}

And here is the error im getting from the Terminal:

ise@ubuntu:~/Desktop$ make

gcc -c main.c defs.c gameIO.c zeroPlayer.c twoPlayer.c

gcc gameIO.o defs.o zeroPlayer.o main.o twoPlayer.o -o prog

ise@ubuntu:~/Desktop$ ./prog 1 2 "l.txt" 3

2 is 2 1 is 1 4 is 3 name of file is l.txt 

Segmentation fault (core dumped)

Very strange, as you can see my program dosen't enter my first "if", but you can see it prints the line before the if statment.

thanks for any help!

Aucun commentaire:

Enregistrer un commentaire