Question

I am new to programming in C and I have the following task to complete:

Write a program that reads from a file with three numbers. First two numbers represent the height and width of a rectangle generated using asterisks (*). The third number represents a recurring gap among the (*) on each row of the rectangle.

Example file layout 5 8 3

Console output

** ** **
** ** **
** ** **
** ** **
** ** **

... I am OK when it comes to reading the file, I have just hit a road block when it comes to replacing the numbers with asterisks and adding a space. I understand that I should be looking at learning loops probably a for for this particular task.

Please could someone give me some good websites, reading material or code hints where I can try and learn about loops, there are so many websites out there I just wondered where the best place for a begginer in C such as myself should go to learn quickly and efficiently.

Any recommendations would be great :)

Thank you!

Was it helpful?

Solution

Two nested for loops, the outer for lines and the inner for columns. In the inner, add a check that for every N (where N is the third number) you print a space instead of an asterisk.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top