0

expected ‘int’ but argument is of type ‘char *’ dont know how to correct, any suggestion

#include <stdio.h>

int my_strncmp(char const *s1, char const *s2, int n);

int main (int ac, char **ag) {
    char result;

    if (ac == 4) {
        result = my_strncmp(ag[1], ag[2], ag[3]);
        printf("%d\n", result);
    }   
    return(0);
}
0

3 Answers 3

3

You need to convert ag[3] (of type char * / string) to an integer.

Have a look at strtol() and its brethren. With atoi() exists a simpler function, which however is not as robust and versatile. That is why I would recommend getting into the habit of using strtol() et al., always.

Sidenote, "n" parameters are usually made size_t (unsigned) instead of int. (Compare strncmp()). You'd use strtoul() then.

Sign up to request clarification or add additional context in comments.

Comments

0

The last parameter of my_strncmp is defined as an int n, yet when it is called in main the third parameter is char * type

Comments

0

in here,

int my_strncmp(char const *s1, char const *s2, int n);

the last part is int n

result = my_strncmp(ag[1], ag[2], ag[3]);

but here what you are passing ag[3] is of type char

hope this helps..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.