Front Office Football Central  

Go Back   Front Office Football Central > Archives > FOFC Archive
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 03-11-2005, 05:53 PM   #1
Karim
College Starter
 
Join Date: Oct 2000
Location: Calgary
C++: Arbitrary File Input

I can open a file when the filename is hard coded or if I ask the user and store the filename into a string. But I have no idea how to open a file when the filename is only specified at run-time on the command line. For instance:

myProg filename1
myProg filename2
etc.,

myProg needs to input the text from the various files for processing but I don't know how to get at the contents. This isn't redirection either which I would be fine with.

Any ideas?

Karim is offline   Reply With Quote
Old 03-11-2005, 05:56 PM   #2
CraigSca
Pro Starter
 
Join Date: Jul 2001
Location: Not Delaware - hurray!
It's been years since I programmed in C, but isn't this part of the main function? Like, argv() and argc()?
__________________
She loves you, yeah, yeah, yeah, yeah!
She loves you, yeah!
how do you know?
how do you know?

CraigSca is offline   Reply With Quote
Old 03-11-2005, 06:17 PM   #3
gstelmack
Pro Starter
 
Join Date: Oct 2000
Location: Cary, NC
Yup, you need to use the argc and argv parameters to main. argc is the parameter count, and argv is an array of strings that are the command-line parameters tokenized by whitespace.
__________________
-- Greg
-- Author of various FOF utilities
gstelmack is offline   Reply With Quote
Old 03-11-2005, 07:59 PM   #4
Karim
College Starter
 
Join Date: Oct 2000
Location: Calgary
Thanks... something I hadn't seen before.
Karim is offline   Reply With Quote
Old 03-11-2005, 08:26 PM   #5
MikeVic
Head Coach
 
Join Date: Mar 2003
Location: Hometown of Canada
I believe array slot 2 has the first command line specified? The first one is the name of the program or something?
MikeVic is offline   Reply With Quote
Old 03-11-2005, 09:15 PM   #6
gstelmack
Pro Starter
 
Join Date: Oct 2000
Location: Cary, NC
Well, technically it's array slot 1, since C/C++/C# use zero-based indexing ;-)

So if argc == 1, there are no arguments, just the name of the program in argv[0].
__________________
-- Greg
-- Author of various FOF utilities
gstelmack is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 12:20 AM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.