Using Command Line Arguments to Create a File Name

Joined
Dec 19, 2009
Messages
2
Reaction score
0
Hi, as the school year winds to a close, I find myself studying furiously for a class which has been...harder... then most for me. I have a real quick question, how do I take an argument from argv and make it a filename? For example, if my program is called "DistanceRan" and I want to record the distance George has run, my command line would read

./DistanceRan George

How would I make a program which creates Stan.txt? I've tried some things, but as you can tell, I am totally incompetent when it comes to programming, even after a semester of it.

Something I've tried is:


#include <stdio.h>
int main(int argc, char *argv)
{
if (argc>1)
{
char argv[]="%s";
char filesname[sizeof(argv+500);
sprintf(filesname, argv, argv[1]);
}
return 0;
}

but I get the error "no input files." Help please?

Thank you guys so much, from what I've read while lurking, you really know your stuff.
 
Joined
Dec 19, 2009
Messages
2
Reaction score
0
Wow I really misread what he gave us to study. I don't have to create a file I just need to open a preexisting file named George.txt. Haha, anyways... thanks for the help :p
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top