Solved

Eclipse CDT arguments passing.

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

786 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