Testing for the presence of a character in an string in C

Posted by Prab on Stack Overflow See other posts from Stack Overflow or by Prab
Published on 2010-05-17T04:14:11Z Indexed on 2010/05/17 4:20 UTC
Read the original article Hit count: 171

Filed under:

What's wrong with this?

#include <stdio.h>

void main(){
    char *s="some text";
    printf("%d",is_in(s,'t'));

}

int is_in(char *s, char c){
    while(*s){
        if(*s==c) return 1;
        s++;
    }
    return 0;
}

I get the following compile time error with GCC:

test.c:9: error: conflicting types for ‘is_in’

test.c:9: note: an argument type that has a default promotion can’t match an empty parameter name list declaration

test.c:5: note: previous implicit declaration of ‘is_in’ was here

© Stack Overflow or respective owner

Related posts about c