创建函数脚本(前面的空格,选中的字符和打印的时间)

时间:2017-02-09 01:40:56

标签: c

我有一次尝试,但是这个网站不会让我正确地缩进它并且我一直在收到错误 编写一个名为script的函数的原型,该函数有三个输入参数。 第一个参数是在a开头显示的空格数 线。第二个参数是空格后显示的字符,和 第三个参数是显示第二个参数的次数 在同一条线上。

    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);

   }

上面的这一行是问题行,我无法弄清楚如何打印

之前的空格

1 个答案:

答案 0 :(得分:1)

  

为一个名为script的函数编写原型,该函数有三个输入   参数。

     

如何在前面打印空格?

带参数和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);
        }

}

这不会有任何错误。