dimanche 29 mars 2015

What's the type of "precision" specifier for printf()


Suppose I use the following printf() specifier string:



printf("%.*s", length, str);


which asks printf() to print the first length characters in str . The question is which type length has? I only see brief mentions of integer number in the documentation.


So it looks like it is int. Then it looks like I cannot use the following code when a string is very long:



const char* startOfString = ...
const char* middleOfString = ...
printf("%.*s", (int)( middleOfString - startOfString ), startOfString);


It looks like I cannot output more than INT_MAX characters this way.


So which type is precision? Is it int or is it size_t or anything else?




Aucun commentaire:

Enregistrer un commentaire