1
我在c.Below中使用零左墊是實現代碼。在c中有0的右墊字符串
unsigned char* LeftPadZero(unsigned char fa[], int flen)
{
unsigned char *fout;
int sz;
sz = snprintf(NULL,0,"%s",fa);
fout = (unsigned char*)malloc(flen+sz+1);
if(flen > 0)
{
sprintf((char*)fout,"%0*d%s", flen , 0, fa);
}
else if(flen == 0)
{
fout = fa;
}
else
{
printf("Length of number is negative\n");
return NULL;
}
return fout;
}
現在我正在嘗試爲Right零點pad.But而不是填充與0填充長度正在打印。 EX:string000這種方式應該print.In我的情況下,它被打印成STRING3
unsigned char* RightPadZero(unsigned char fa[], int flen)
{
unsigned char *fout;
int sz;
sz = snprintf(NULL,0,"%s",fa);
fout = (unsigned char*)malloc(flen+sz+1);
if(flen > 0)
{
sprintf((char*)fout,"%s%0*d", fa , 0, flen);
}
else if(flen == 0)
{
fout = fa;
}
else
{
printf("Length of number is negative\n");
return NULL;
}
return fout;
}
非常感謝你,現在就開始工作。 –