Solved

Eclipse CDT arguments passing.

Posted on 2004-09-20
4
932 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

867 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

18 Experts available now in Live!

Get 1:1 Help Now