Solved

Eclipse CDT arguments passing.

Posted on 2004-09-20
4
926 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:nOOgz
  • 2
  • 2
4 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12100352
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
 
LVL 1

Author Comment

by:nOOgz
ID: 12100613
Hi Sunny,

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

thanks :)
nOOgz
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 50 total points
ID: 12100818
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
 
LVL 1

Author Comment

by:nOOgz
ID: 12101286
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now