Solved

command-line arguments

Posted on 1997-05-05
5
281 Views
Last Modified: 2010-04-15
I`m learning C using the Waite`s group New C Primer Plus book, and using Microsoft`s Visual C++ ver. 4.0, on a pentium 120. I`m up to chapter 11, and all has gone well so far. On entering the first test program at the end of Chap. 11, using command-line arguments, the programs will not do what the book says they should. All they do is write the command path on the screen, as if the commands are not properly recognized or something.. I have tried other examples further on with the same results, and have checked in the help in the program, and there is nothing I can find that gives me any clues as to why these programs are not responding properly. I was hoping you could help me out. I would greatly appreciate any info you can supply. Thank`s in advance !!
Bruce Pigeon
Quebec, Canada
(aspiring programmer)
0
Comment
Question by:pigeonbr
5 Comments
 
LVL 2

Expert Comment

by:mlev
ID: 1250261
It would have helped if you posted an example of a program you have problems with.
0
 

Expert Comment

by:bill.m
ID: 1250262
If we don't have either of your books, there's no way to help
you.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1250263
What is the program supposed to do with the arguments?

Please provide the sample code and a brief synopsis of what SHOULD be happening.  Its a bit hard help you make the program do what it is supposed to if we don't know what that is :-)

If you want you can eMail me your code at Roger_Onslow@compsys.com.au and ensure you include a description of what it is supposed to do.

0
 

Accepted Solution

by:
cwestin earned 70 total points
ID: 1250264
I don't know those particular books.  You may be falling prey to differences in the handling between the way Unix handles command-line args, and the way windows does; your books may be describing one behavior, while you're using the other system.  To see what's going on, you can write a very stupid program, like the Unix "echo" command:

int main(int argc, char *argv[])
{
  int i;

  for(i = 0; i < argc; ++i)
    printf("argv[%d] -> \"%s\"\n", i, argv[i]);
}

Using this, you can just look at the command-line arguments to see what is being passed in.  (You could just prepend this code to your program.)

The difference in handling that I've had to deal with before is that the Unix shells "glob" or expand wildcards, while the DOS box does not.  Therefore,

prog *.c

On UNIX, argv gets all the .c files in the current directory.  On Windows/Dos, argv[1] == "*.c".

Try using this code fragment just to see if your program is getting the right arguments in the first place, before you worry about anything else.

0
 

Author Comment

by:pigeonbr
ID: 1250265
I did discover what I was doing wrong thanks to your advice. Thank you very much. I appreciate your service.
Bruce Pigeon
Quebec, Canada
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

685 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