#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char a[10];
memset(a, 0x00, sizeof(a));
sprintf(a, "012");
printf("[%s]\n", a);
printf("[%6s]\n", a);
printf("[%.6s]\n", a);
printf("[%-6.6s]\n", a);
}
# a.out
--------------------
[%s] 결과[012]
[%6s] 결과[ 012]
[%.6s] 결과[012]
[%-6.6s]결과[012 ]
--------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char a[10];
memset(a, 0x00, sizeof(a));
sprintf(a, "0123456789");
printf("[%s]\n", a);
printf("[%6s]\n", a);
printf("[%.6s]\n", a);
printf("[%-6.6s]\n", a);
}
# b.out
--------------------
[%s] [0123456789]
[%6s][0123456789]
[%.6s][012345]
[%-6.6s][012345]
--------------------