How to repeat a char using printf?

前端 未结 12 1165
难免孤独
难免孤独 2020-11-28 03:24

I\'d like to do something like printf(\"?\", count, char) to repeat a character count times.

What is the right format-string to accomplish

12条回答
  •  情深已故
    2020-11-28 04:29

    you can make a function that do this job and use it

    #include 
    
    void repeat (char input , int count )
    {
        for (int i=0; i != count; i++ )
        {
            printf("%c", input);
        }
    }
    
    int main()
    {
        repeat ('#', 5);
        return 0;
    }
    

    This will output

    #####
    

提交回复
热议问题