How can I print multiple character with one printf?

Shift Loader

I want to print multiple character using printf. My approach up to now is this-

#include <stdio.h>

int main()
{
    printf("%*c\n", 10, '#');

    return 0;
}

But this only prints 9 spaces before the #.

I want to print it like this-

##########

I am unable to figure out how to do this. Please help me?

Dipu

You can not use printf like that to print repetitive characters in Ansi C. I suggest you to use a loop like this -

#include <stdio.h>

int main()
{
    int i;
    for(i = 0; i < 10; i++) putchar('#');

    return 0;
}

Or if you have absolutely no desire to use loops, you can do something like this-

#include <stdio.h>
int main()
{
    char out[100];
    memset(out, '#', 10);
    out[10] = 0;
    printf("%s", out);

    return 0;
}

By the way, using printf like this also works-

#include <stdio.h>

int main()
{
    printf("%.*s", 10, "############################################");

    return 0;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to use printf to print a character multiple times?

From Dev

How to use printf to print a character multiple times?

From Dev

How to print the "%" character with printf?

From Dev

How to print the "%" character with printf?

From Dev

how can I print multiple rows data in one column?

From Dev

How can I print one page enlarged to multiple pages?

From Dev

How can I print the address of first character?

From Dev

How can i print string one by character without space between them IN python2.7?

From Dev

How can I make Word print a one-page document multiple times on one single sheet?

From Dev

how can I strcat one character to array character in c++

From Dev

How come I can print out each character separately but not as a whole?

From Dev

How come I can print out each character separately but not as a whole?

From Dev

How can I overwrite multiple lines with echo or printf in shell?

From Dev

Can I print an object of the class using printf()?

From Dev

printf: can't print less than 1 character with %*c

From Dev

How can I make echo or printf in shell ignore a double backslash (\\) and print it as I see it

From Dev

How Can I Merge Multiple Directories into One

From Dev

How Can I Merge Multiple Directories into One

From Dev

How can I add multiple functions into one?

From Dev

How do I print multiple images to one page on Chrome OS?

From Dev

How to print a single character from an array of strings using printf?

From Java

How can I print the log for a branch other than the current one?

From Dev

How can I print a string while another one keeps printing?

From Dev

How can I print a one dimensional array as grid in Python?

From Dev

How can I print all content of an array in one line?

From Dev

How can I print only one row with specific id in Laravel?

From Dev

how can I rename multiple files by inserting a character?

From Dev

How can I split a character string in a dataframe into multiple columns

From Dev

how can I rename multiple files by inserting a character?

Related Related

  1. 1

    How to use printf to print a character multiple times?

  2. 2

    How to use printf to print a character multiple times?

  3. 3

    How to print the "%" character with printf?

  4. 4

    How to print the "%" character with printf?

  5. 5

    how can I print multiple rows data in one column?

  6. 6

    How can I print one page enlarged to multiple pages?

  7. 7

    How can I print the address of first character?

  8. 8

    How can i print string one by character without space between them IN python2.7?

  9. 9

    How can I make Word print a one-page document multiple times on one single sheet?

  10. 10

    how can I strcat one character to array character in c++

  11. 11

    How come I can print out each character separately but not as a whole?

  12. 12

    How come I can print out each character separately but not as a whole?

  13. 13

    How can I overwrite multiple lines with echo or printf in shell?

  14. 14

    Can I print an object of the class using printf()?

  15. 15

    printf: can't print less than 1 character with %*c

  16. 16

    How can I make echo or printf in shell ignore a double backslash (\\) and print it as I see it

  17. 17

    How Can I Merge Multiple Directories into One

  18. 18

    How Can I Merge Multiple Directories into One

  19. 19

    How can I add multiple functions into one?

  20. 20

    How do I print multiple images to one page on Chrome OS?

  21. 21

    How to print a single character from an array of strings using printf?

  22. 22

    How can I print the log for a branch other than the current one?

  23. 23

    How can I print a string while another one keeps printing?

  24. 24

    How can I print a one dimensional array as grid in Python?

  25. 25

    How can I print all content of an array in one line?

  26. 26

    How can I print only one row with specific id in Laravel?

  27. 27

    how can I rename multiple files by inserting a character?

  28. 28

    How can I split a character string in a dataframe into multiple columns

  29. 29

    how can I rename multiple files by inserting a character?

HotTag

Archive