LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 05: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, 07:01 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,379

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
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, 08: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 11:30 AM
how to change and pass thread parameter back to main dragondad Programming 3 09-19-2005 01:58 PM
Make g++ pass my file before others to ld ta0kira Programming 18 07-15-2005 10:12 AM
how do you reload the 'main' method in Java? ludeKing Programming 1 05-29-2004 10:22 PM
best method to replace data in a text file? gsbarry Linux - General 5 04-15-2003 08:21 AM


All times are GMT -5. The time now is 07:52 PM.

Main Menu
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