C语言的输出printf内的输出格式控制问题!

#include <stdio.h>
int main(void)
{
char max[20];
scanf("%s",max);
printf("===========\n");
printf("\"%s\"\n",max); //比输出的字符宽3个字段要怎写?求指点! (就是不管输出什么都多3个字段)
return 0;
}

第1个回答  2015-05-02
按你的意思,这样写就行了:
printf("%s ",max);
第2个回答  推荐于2016-04-25
printf("\"%*s\"\n",strlen(max)+3,max);

追问

直接复制没贴显示:
/home/msn/codeflie/2.c: 在函数‘main’中:
/home/msn/codeflie/2.c:9:2: 警告: 字段宽度限定 ‘*’ expects argument of type ‘int’, but argument 2 has type ‘size_t’ [-Wformat]
错在哪里,求详细解说!谢谢!

追答#include <stdio.h>
#include <string.h>
int main(void)
{
    char max[20];
    scanf("%s",max);
    printf("===========\n");
    printf("\"%*s\"\n",(int)strlen(max)+3,max);    //比输出的字符宽3个字段要怎写?求指点! (就是不管输出什么都多3个字段)  
    return 0;
}

追问

为什么只有在strlen前面+上int才不会出错啊?

本回答被提问者采纳
第3个回答  2015-05-03
直接加空格就行啊