11 Answers
New AnswerIf someone inputs a string of lets say, 10 charaters, id like the compiler to pick the first 8 characters followed 5 blanks
Is there a printf format for that? Ive seen printf commands like printf(‘%5s’, ‘helloworld’)
Ive gotten the answer guys printf("%5.8s\n", "Hello World\n"); /* Right-justify string with space for 15 chars, print only first 10 letters */ Thank you so much
if you want to print "Hello" with a indent of 8 characters: printf("%13.5s", "Hello World\n"); Output: Hello ................. Here's how it works: 13 is the length of the line, 5 is the number of characters in "Hello", 13-5 = 8 is the number of characters indent.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message