<分区>
我有以下程序:
#include <stdio.h>
#include <stdlib.h>
int main()
{
static char string[12];
int length,c,d;
printf("Enter a string :");
gets(string);
length=strlen(string);
printf("\nLength of the string is %d",length);
for(c=0;c<=length-2;c++)
{
d=c+1;
printf("\t%.*s\n",d,string);
}
for(c=length;c>=0;c--)
{
d=c+1;
printf("\t%.*s\n",d,string);
}
}
我对 printf
语句中 %.*s
的用法感到非常困惑。我知道 %s
用于显示字符串,但我对这个程序中 s
之前的 .*
的用法感到困惑。此外,在 printf 语句的引号内只提到了一种数据类型 (%s
),但在 printf
语句中提到了两个变量。