c - Is there a better way to find length of any String or a Number? -


here 1 way problem unnecessary usage of output screen.

lenth=printf("%d",num);// or lenth=printf("%s",str); 

how find length without having output printf?

you can use snprintf() empty buffer (i.e. pass null pointer), return number of characters have been written buffer if there enough space in it:

int length = snprintf(0, 0, "%d", num); 

this way, don't need use actual buffer , won't print on stdout printf() does.


Comments

Popular posts from this blog

jsf - How to order SelectItems in custom renderer extending MyFaces HtmlMenuRenderer -

Android : Making Listview full screen -

c# - How to share session between a MVC project and a WCF project? -