Reputation: 53
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);
}
Upvotes: 0
Views: 621
Reputation: 9
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..
Upvotes: 0
Reputation: 70223
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.
Upvotes: 3
Reputation: 608
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
Upvotes: 0