Open & pass data onto a file on cmd line

Hi I been reading lots on how to use argc and argv, and have managed to get some data be passed on argv
argv[1] = 234
argv[2] = 323 etc, now I have a problem, I want all of this data to be passed onto a file but really dont know how to.. First of all how to allocate the text file where this data is gonna be stored from my program and then I'm not sure if by just doing an ./a.out filename.c 234 323 is going to pass the data straight onto the file.. Please someone explain this to me..

This is the code Im working on im sure its totally wrong, but hey, you dont learn unless you try.

"Only those who will risk going too far can possibly find out how far one can go." -- TS Eliot.

1. argc is the number or arguments on the command line, including the name of the program. So, if you type "./a.out filename.c 234 323 <Enter key>" the value of argc will be 4. The test for argc in your program will be wrong. Instead of testing for 2 it should test for > 1

Code:

if( argc > 1)
filename = argv[1];

2. The same file can not normally be opened twice -- if the first fopen() succeeds then the second is probably going to fail. If you want the file for both reading and writing then open it once and specify "r+", "w+", or "a+", depending on how you want it opened. see man pages or msdn for description of these flags.