字符串右补零

想得到16位的数据进行加密,但时间戳获取到的是10位,要求是右补零,不能左补零。

以下是一个自己尝试成功的例子:

#include <stdio.h>
#include <time.h>
#include <string.h>


int main(void)
{
        time_t t;
        char buf[16]={0};
        t =time(NULL);
        int curtime = time(&t);
        printf("curtime = %d\n",curtime);
        char str[16];
        sprintf(str,"%d",curtime);
        //sprintf(buf,"%d",curtime);
        sprintf(buf,"%-d%0*d",curtime,16-strlen(str),0);
        printf("buf len = %d , buf : %s\n",(int)strlen(buf),buf);


        return 0;
}

字符串右补零

字符串右补零