Typing error [closed]

-3

I took a C book to study, however, it is a bit outdated, and I came across the following code:

#include<stdio.h>

is_in(char *s, char c);

void main(void){
is_in("olac", "ola");
}

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

link
Can someone help me?

    
asked by anonymous 15.03.2017 / 11:58

1 answer

3

On compilation error, there are missing the types in the prototype and function declaration:

int is_in(char *s, char c);

In the method call, you are passing a character string instead of a char.

is_in("olac", "ola");

The GCC compiles the code, but can not transform the inserted string. The correct would be:

is_in("olac", 'o');

Remembering that char always stays within plics (').

And about what the code does: it checks to see if a given character is present within a string. If positive, returns 1 (true); 0 negative (false) case.

    
15.03.2017 / 13:09