?
Solved

command-line arguments

Posted on 1997-05-05
5
Medium Priority
?
290 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 140 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 opening and reading files 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.
Suggested Courses

809 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