?
Solved

Eclipse CDT arguments passing.

Posted on 2004-09-20
4
Medium Priority
?
953 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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 and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

719 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