How to repeat a char using printf?

前端 未结 12 1195
难免孤独
难免孤独 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条回答
  •  Happy的楠姐
    2020-11-28 04:27

    #include 
    #include 
    
    void repeat_char(unsigned int cnt, char ch) {
        char buffer[cnt + 1];
        /*assuming you want to repeat the c character 30 times*/
        memset(buffer,ch,cnd); buffer[cnt]='\0';
        printf("%s",buffer)
    }
    

提交回复
热议问题