Web lists-archives.com

[Mingw-users] snprintf buggy in gcc 4.9.3-1




Using the conversion %02d or %2d should produce a string of (at 
least) 2 characters.
However when the number to be printed has only one digit snprintf 
produces a field width of 1
A workaround is to use _snprintf.

gcc.exe (GCC) 4.9.3-1 as obtained by mingw-get on juli 30 2016
windows-10 64-bit

Regards, Peter
==============================
testprogram:

#include <stdio.h>
#include <string.h>
int main()
{
   char string[8];

//snprintf() drops the leading 0 in mingw gcc 4.9.3-1 !!
   snprintf(string,7,"%02d",3);
   printf("snprintf:\tstring=%s len=%d\n",string,strlen(string));

// with _snprintf() no problem
   _snprintf(string,7,"%02d",3);
   printf("_snprintf:\tstring=%s len=%d\n",string,strlen(string));

   return 0;
}
================================
Program output

snprintf:       string=3 len=1
_snprintf:      string=03 len=2


------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe