Segfault on char comparison in C

cxzp

I have the following code:

void click(int x, int y, zbar_window_t *window, ZBarGtk *self) {
    char* response = handle_click_events(x, y, window);
    printf("RESPONSE + %s\n", response);
    printf("%c\n", response[0]);
    if (response[0] == "0") {                                 //CRASHES HERE
        printf("inside \n");
        printf("%s\n", response++);
        g_signal_emit(self, self->enumACTIVE, 0, -1, response++);
    }
    else {
        g_signal_emit(self, self->enumACTIVE, 0, -1, response++);
    }
}

It keeps on crashing on the stated line.

Don't You Worry Child

Replace this:

if(response[0] == "0")

with:

if(response[0] == '0')

"0" is a string, '0' is a character. You should not compare strings using ==.

Also, you should check if response is NULL after this statement:

char* response = handle_click_events(x, y, window);

otherwise printf("%c\n", response[0]); may crash again.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

C : char **에 realloc이있는 SEGFAULT

분류에서Dev

My logic is failing me (C++, nslookup, char comparison)

분류에서Dev

C에서 char * 배열에 쓰면 segfault가 발생합니다.

분류에서Dev

C Segfault in readdir after chdir

분류에서Dev

C-fgets는 char 배열을 사용할 때 신비하게 segfault를 발생시킵니다.

분류에서Dev

Errors in binary comparison in C

분류에서Dev

chdir 후 readdir의 C Segfault

분류에서Dev

C++: string = NULL gives SEGFAULT 11?

분류에서Dev

C에서 segfault로 실행

분류에서Dev

왜 (char) + (char) = (int) in C?

분류에서Dev

C *char pointer to char array

분류에서Dev

c++ string comparison in if statement

분류에서Dev

malloc없이 char * str에 들어가고, segfault가 없습니까?

분류에서Dev

malloc'd char * 해제로 인해 segfault 11 발생

분류에서Dev

병합의 Segfault-C로 정렬

분류에서Dev

C: Passing one dimension of a 2D array results in segfault

분류에서Dev

MPI_Send MPI_Recv segfault in C++

분류에서Dev

C의 이진 검색 트리 SEGFAULT

분류에서Dev

C ++ 연결 목록 segfault 디버그

분류에서Dev

C 가비지 수집기의 segfault

분류에서Dev

긴 정수를 사용하는 C segfault

분류에서Dev

c++ Polymorphism : segfault and reference strange behaviour with arrays

분류에서Dev

문자열 segfault의 C ++ 벡터

분류에서Dev

C 프로그램의 Segfault, malloc 호출

분류에서Dev

C ++ : cin >> * char

분류에서Dev

c의 null char

분류에서Dev

C: Symbols in array of char

분류에서Dev

Behaviour of char pointers in C

분류에서Dev

Char 'apex' C++