Creating a table and I/O file help?

This is a discussion on Creating a table and I/O file help? within the C Programming forums, part of the General Programming Boards category; I'm a bit confused by a problem on some homework for my programming test. I'm not really understanding what the ...

Creating a table and I/O file help?

I'm a bit confused by a problem on some homework for my programming test. I'm not really understanding what the question is asking though, or how to apply it to the text file I'm supposed to be outputting from. I emailed my professor for clarification but I was hoping for some forum help?

There is a file, radius.txt, containing two numbers. The first number is a start point; for the sake of argument, let’s say it’s 0.5. The second number is the number of iterations that a table must contain; let’s agree to call this 5 for now. Now, assume the first number is a radius with which you must find the circumference and area of a circle as well as the volume of a sphere.

Create a table that does this for all iterations described in the file, assuming a user-defined iterative step. Do not assume pi to be previously defined, but do assume that it is a constant defined at 3.14159265. Use proper data types and restrict calculated output to 8 decimal places but radii to 4. Print output to a separate file, circles.txt, as well as the screen.

I would change the f1 variable to something a lot more descriptive, like "radius" maybe, and f2, same thing. Something like "steps2take" or etc. Finally, "stepSize" for the user's input on the size of each step.

I'm not sure what questions to ask... firstly, how do I get it to have an output table like that one (in the program) and also, why isn't it outputting to a txt file like I programmed it to do? My program has errors and I'm not sure how to correct them, I just want to run what I already have and see how well it can be applied to my professors problem.

*The header row of text has to be printed before the for loop.
radius circumf area volume

*the increment for r in each loop has to be the stepSize, it can't be r++.

*Fclose() must be changed to fclose()

*inside the for loop, with each time around the loop, you will have to have the data printed out to the display, and to the file.

*the for loop requires a closing curly brace at the end of it: }

*the for loop requires indentation that matches the rest of your program.

*You'll use printf's format features to make your table up. Don't worry about that much, for now. That is a detail easily handled, later.

DO NOT post code with a poor indentation style. Those kinds of programs are VERY difficult to study, for you, me, and everybody else. Your brain will be slowly training itself to recognize common C idioms if you use proper indentation. Before long, you'll be able to pick out some errors, with just a quick read over. Also, code that looks like something the cat killed and dragged in, is bound to get less help here, and a lower grade from your teacher.

Those errors from the compiler are important, although they are not easy to understand.

I fixed some of the problems you described... I feel like my for loop looks exactly how it should I'm not sure why it isn't written to repeat however many times the user specified... isnt that accomplished in the initial for(,,?

Is my fprintf format not good to print the code to a file after the loop is run?

I tried to fix my indentations as best as possible.. I appreciate the help a lot