Thursday, July 30, 2009

C's sprintf function into a mostly non-initialized char array?

I am converting a function written in C to Java. I have one sticking point due to not being fully familiar with how sprintf works.





In the following example, what will be stored in "buff" after the sprinft call?





Will any of the locations in "buff" have undetermined value if the compiler doesn't add initialization code for the array?





char buff[11]


memset( buff, '0', 4 );


long num


num = 999999;


sprintf( buff, "%08ld", num );

C's sprintf function into a mostly non-initialized char array?
00999999

carnation

No comments:

Post a Comment