1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Printing n copies of a charater to a string

Discussion in 'C' started by boatcatx, Mar 13, 2014.

  1. boatcatx

    boatcatx New Member

    Joined:
    Mar 13, 2014
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Is there a way with no loop to copy say 5 copies of 'r' to a string? I don't see one.
     
  2. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    can you use memset?

    Code:
    char buffer[6] = { 0 };
    memset(buffer, 'r', 5);
    
    puts(buffer);
    
     

Share This Page