samedi 9 mai 2015

C: Segmentation fault when checking IF integer is 0. Why?

I get a segmentation fault every time I hit the statement if(x==0){}. Although it works with any other number. As you can probably tell I'm not too experienced with C. Any help is appreciated.

int line = 0;
int w;
while ((w = read_word(f)) != EOF){
line++;

if (line == 1) {
    printf("\t.orig\tx%x\n", w);        
}

if (line != 1) {

int x = ((w >> 12) & 0xF);
printf("%d\n", x);

//FAULT HAPPENS HERE:
if ( x == 0 ) {
...
}

Aucun commentaire:

Enregistrer un commentaire