Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: how to pass...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 8 Topic 24596 of 27670
Post > Topic >>

Re: how to pass a file to a c program

by "Malcolm McLean" <regniztar@[EMAIL PROTECTED] > Feb 16, 2008 at 01:29 PM

<neha_chhatre@[EMAIL PROTECTED]
> wrote in message news:
> How to pass a text file to a c program ???
>
> Is it using abstract data types?? (eg. using arg v,arg
> c)..........................???
>
You've got two choices.

Either pass in the path to the file on the commandline and, as Army1987 
said, use fp = fopen(argv[1], "r") where fp is a FILE *.

Alternatively, most plarforms allow you to pipe a file to standard input.
So 
you can get the file line by line by calling fgets(), or character by 
character by calling getchar(). You could also call gets(), but that
suffers 
from the problem that long lines might crash your program.

The first method is more common.

-- 
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
 




 8 Posts in Topic:
Re: how to pass a file to a c program
"Malcolm McLean"  2008-02-16 13:29:22 
Re: how to pass a file to a c program
Mark McIntyre <markmci  2008-02-16 16:06:58 
Re: how to pass a file to a c program
Keith Thompson <kst-u@  2008-02-16 09:07:33 
Re: how to pass a file to a c program
"Malcolm McLean"  2008-02-16 18:35:59 
Re: how to pass a file to a c program
Richard Heathfield <rj  2008-02-16 18:41:33 
Re: how to pass a file to a c program
CBFalconer <cbfalconer  2008-02-16 20:12:03 
Re: how to pass a file to a c program
CBFalconer <cbfalconer  2008-02-16 20:08:34 
Re: how to pass a file to a c program
Christopher Benson-Manica  2008-02-19 21:18:01 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 22:05:55 CDT 2008.