gpt4 book ai didi

创建函数脚本(空格开头,字符选择,打印次数)

转载 作者:太空宇宙 更新时间:2023-11-04 03:24:44 24 4
gpt4 key购买 nike

我有尝试,但这个网站不允许我正确缩进,而且我不断收到错误为一个名为 script 的函数编写原型(prototype),该函数具有三个输入参数。第一个参数将是要在开头显示的空格数线。第二个参数将是要在空格后显示的字符,并且第三个参数将是显示第二个参数的次数在同一条线上。

    script();

int main() {

script();

return 0;

}

double script() {

int spaces, timesCharacter;
char character;

printf("Please enter in order the number of spaces preceeding a character\n");
printf("the specific character to input and \n");
printf("the number of times your want the character to display\n");
printf("in order with a space in between each one: \n");

scanf("%d %c %d", &spaces, &character, &timesCharacter);

printf("%d %c %d", spaces, character, timesCharacter);

}

上面这一行是问题行,我不知道如何打印前面的空格

最佳答案

Write the prototype for a function called script that has three input parameters.

how to print spaces preceding?

带有参数和原型(prototype)的函数,看看下面的代码:

#include <stdio.h>

double script(int spaces,char character, int timesCharacter ); //Function Prototype

int main() {

int spaces, timesCharacter;
char character;

script(spaces, character,timesCharacter); //Function Call

return 0;

}

double script(int spaces,char character, int timesCharacter) { //Function Defination



printf("Please enter in order the number of spaces preceeding a character\n");
printf("the specific character to input and \n");
printf("the number of times your want the character to display\n");
printf("in order with a space in between each one: \n");

scanf("%d %c %d", &spaces, &character, &timesCharacter);

//printf("%d %c %d", spaces, character, timesCharacter);

/*How to add spaces preceding*/
printf("%*c", spaces, character);
//To print the number of times
int i=0;
for(i = 1;i < timesCharacter; i++ ){
printf("%c",character);
}

}

这不会有任何错误。

关于创建函数脚本(空格开头,字符选择,打印次数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42126819/

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