I am writing the code for problem set 1 and I was searching for a technique that allows me to repeat a character a specified number of times according to the value of a variable. I found one :

printf("%.*s", 5, "=================");

This will print


It worked perfectly for my code. So Is it okay that I used a technique that I found online? Or do I have to find another way to solve it? And if is it okay could someone explain what does the dot (.) after the (%) mean?


No it's not considered cheating. You can use any way you want to achieve the required result, as long as not you don't use someone else's work. We all search the web for little and big code examples and how to use them. Every programmer does.

That said, as Ashish Patel has said, it would be better to follow the instructions in the walkthroughs, as they are there to teach you something for your next psets.

The reason I write this as a separate answer, is to answer your other question, about the . in the printf().

According to cppreference.com:

(optional) . followed by integer number or *, or neither that specifies precision of the conversion. In the case when * is used, the precision is specified by an additional argument of type int. If the value of this argument is negative, it is ignored. If neither a number nor * is used, the precision is taken as zero. See the table below for exact effects of precision.

and the table bellow for the s modifier specifies:

Precision specifies the maximum number of bytes to be written. If Precision is not specified, writes every byte up to and not including the first null terminator.

Feel free to visit the site and make yourself more comfortable with printf(). You will use it a lot. :)

Happy Coding!


Even though there is no harm in looking for help online as long as you don't copy & paste complete solutions, it is very important to understand the algorithms and how to solve such problems systematically. So go through the walkthrough videos, and source code provided by CS50 and follow the instructions.

  • but i only used a technique as I searched for how to repeat a character for a number of times according to a variable. I didn't copy it as if someone said it is the solution for pset1. or do I have to use what was introduced in cs50 only? – Lina Tewala Aug 21 '16 at 10:08
  • 1
    I think what the previous poster meant when he told you to follow the instructions is that if you just find a completely different solution online, you're not going to learn the things that the pset is trying to teach you (like loops etc.). This might become a problem later, because each new pset requires you to have a good understanding of material from the previous psets as well. – iCode95 Aug 21 '16 at 11:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .