c - Using sizeof with char *array[] -
i new programming. learning c , java.
i have array -
char *array = {"zero", "one", "two", "three"}; from link can print array content -
printf("%s %s", array[0], array[1]); //zero 1 but question how can print length of referenced array[0], array[1] , on. know can thing -
printf("%d\n", sizeof("zero"); but can print size using array variable itself.
i have tried different ways -
printf("%d\n", sizeof(array[0]); //4 printf("%d\n", sizeof(*array[0]); //1 but each time wrong answer.
thanks
you need strlen.
printf("%d\n", (int) strlen(array[0]));
Comments
Post a Comment