Solved

command-line arguments

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.
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.

777 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