• C

Eclipse CDT arguments passing.

Hi,

I have the newest CDT of eclipse 3.0 and i'm trying to pass a file as argument to my little app.

i have set the field that says 'arguments' under a new 'run' in eclipse to myfile.txt (alsp tried < myfile.txt)
and the working directory to the directrory which contains that file.

in my code i have this fun stuff:
int main (int argc, char *argv[]){

 while (fgets (buffer, sizeof(buffer), stdin)){
   printf("%s\n",buffer);
  }
}

however, if i run that, it seems to be in a loop for ever.
Do i need to add some  sort of EOF or \n to the commandline arguments in eclipse?
i didn't really find anything useful thru google.

any help is greatly apprechiated.

~/nOOgz
LVL 1
nOOgzAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
sunnycoderConnect With a Mentor Commented:
No ...

Command line arguments are given to the program by the system as soon as program starts. e.g. if you called a program like

./my_program arg1 arg2 arg3

then arg1 arg2 and arg3 are the command line arguments and you do not have to supply them again to the program. Anything more that you write will go in as user input and not command line arguments

refer to this for a simple example and explanation
http://www.cs.cf.ac.uk/Dave/C/node12.html#SECTION001220000000000000000
0
 
sunnycoderCommented:
Hi nOOgz,

command line arguments are not read from stdin ....

The while loop in your program is reading user input and not command line arguments. Command line arguments hae already been supplied to prgram as argv array

for ( inti=0; i<argc; i++ )
    printf ("%s\t",argv[i]);

<myfile.txt is also stdin redirection and not command line arguments

Sunnycoder
0
 
nOOgzAuthor Commented:
Hi Sunny,

i see, and what would i then need to do,
that the 'argument' file gets passed to fgets then?

thanks :)
nOOgz
0
 
nOOgzAuthor Commented:
thanks for your help, sunny.

i'll look into this, i think i'll be abled to solve my problem.

if i run my code under linux it works that way tho.

anyways,
take care :)

nOOgz
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.