When I pass a char array through a method and use the sizeof method, it comes out different than if I were to use sizeof directly. Anybody know why and how I can fix this simple mistake?
#include <stdlib.h>
int main()
{
char c[5];
char car[] = { 'a', 'b', 'c' };;
int num = my_strlen(c);
printf("%d \n", sizeof(c));
printf("%d \n", sizeof(car));
printf("%d \n", my_strlen(c));
printf("%d \n", my_strlen(car));
return 0;
}
int my_strlen(char s[]) // returns number of characters in a string
{
return sizeof(s);
}
Output:
5
3
8
8