Need help with a turbo c program....urgent plz help

This is a discussion on Need help with a turbo c program....urgent plz help within the C Programming forums, part of the General Programming Boards category; dear friends,
i have this assignment for class which is getting on my nerves every time i try to write ...

Need help with a turbo c program....urgent plz help

dear friends,
i have this assignment for class which is getting on my nerves every time i try to write the program.
the program is as follows...

there will be a variable 'n' which must be entered by the user. For example if a value of 7 is entered for 'n', then in the display it will print a sand-clock consisting of 7 stars on the first line. 5 stars in the second line. 3 stars in the third line. and 1 star in the fourth line. after that it will increase again like before. like 3 stars on the fifth line. 5 stars in the sixth line. and again seven stars in the seventh line.

1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

> For example if a value of 7 is entered for 'n', then in the display it will print a sand-clock consisting of 7 stars on the first line.
So can you do that - yes or no?
Input an integer (say 7), and print that many *'s using a loop?

> 5 stars in the second line. 3 stars in the third line. and 1 star in the fourth line
Can you write a loop which prints 7, 5, 3, 1 ?
If you can, can you merge that with the first loop, to print a variable number of *'s ?

The rest is easy if you can get that far.

Otherwise, relax knowing that future (and much harder) homework will be of no trouble to you.

1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

@ rags_to_riches :brother the thing is i m totally new at programming. so may be my instructor thought its better to take the stairs rather than taking the elevator.

@ Salem: brother i have problems in understanding the for loop fully. And tell you what , my instructor is a SONOFA........... everytime i ask him to explain it in a clearer way, he reply me to try my self.

That SOB instructor is right, though. Programming (after you learn the basic syntax and logic for the language), is about problem solving, and this is a simple problem.

Think of it like you would do it yourself, with paper and pencil. What steps would you take, in simplest terms?

Write it down - that's the start of your pseudo code, right there. Now start working your pseudo code, into rough code. Leave out the details, for now, whenever feasible. Get the flow, the broad strokes of logic and functions and blocks of code, worked out: input, processing, output - whatever you think is right.

Now polish the code, and add in your details. What I'm emphasizing is that you need to organize your thoughts on the problem - get to know the problem like the "back of your hand", and THEN you'll be able to follow these steps to make your program.

You may not like your instructor now, but you'll appreciate the results, when you work this problem, through. Every Coach has to push his athletes, to get the best out of them. Same with a good instructor.

1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.