gpt4 book ai didi

c - %.*s 在这个程序中有什么用

转载 作者:太空狗 更新时间:2023-10-29 14:55:06 26 4
gpt4 key购买 nike

<分区>

我有以下程序:

#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 语句中提到了两个变量。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com