Solved

command-line arguments

Posted on 1997-05-05
5
273 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
Comment Utility
It would have helped if you posted an example of a program you have problems with.
0
 

Expert Comment

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

Expert Comment

by:RONSLOW
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
memory mapped I/O query 6 136
Problem with form project 66 313
Problem to save 10 120
Using popen() and gunzip() to open file in HTTPServer 6 12
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 and use structures 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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now