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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -