Solved

command-line arguments

Posted on 1997-05-05
5
280 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

808 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