LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-20-2002, 06:14 PM   #1
shassouneh
Member
 
Registered: Apr 2001
Location: Cheney, WA
Distribution: SuSE Linux Professional 9.2
Posts: 556

Rep: Reputation: 30
How to pass a file name into the main Method (C/C++)


Dear All,
I wish to pass the name of a file into the main function such that the program can be called like this:

programname filename.

I want to write a simple program to count the number of lines of text in a text file. So the syntax should be something like:

linecounter filename

Any ideas please?
 
Old 06-20-2002, 08:01 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
how about you look at a C manual for a start? ideas such as this a pretty fundamental to C, getting to grips with them is a must.

anyway... you get the main(int argc, char **argv) line, so argc is teh number of parameters or whatever, and the argv is a pointer to the array of parameters. just access those two vairables and pull out the data you need and go willd with fopen() and such like
 
Old 06-20-2002, 09:07 PM   #3
shassouneh
Member
 
Registered: Apr 2001
Location: Cheney, WA
Distribution: SuSE Linux Professional 9.2
Posts: 556

Original Poster
Rep: Reputation: 30
cool. thanx
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass file adnanm Linux - Newbie 1 11-18-2005 12:30 PM
how to change and pass thread parameter back to main dragondad Programming 3 09-19-2005 02:58 PM
Make g++ pass my file before others to ld ta0kira Programming 18 07-15-2005 11:12 AM
how do you reload the 'main' method in Java? ludeKing Programming 1 05-29-2004 11:22 PM
best method to replace data in a text file? gsbarry Linux - General 5 04-15-2003 09:21 AM


All times are GMT -5. The time now is 01:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration