[C] parsing command line switches
From: Marlene Stebbins (stebbins_at_email.com)
Date: 01/26/04
- Next message: Josh Sebastian: "Re: open file with arbitrary name"
- Previous message: cald: "Derived Class from a base class..."
- Next in thread: Robert W Hand: "Re: [C] parsing command line switches"
- Reply: Robert W Hand: "Re: [C] parsing command line switches"
- Reply: Jason: "Re: [C] parsing command line switches"
- Reply: Arthur J. O'Dwyer: "Re: [C] parsing command line switches"
- Reply: Martijn Lievaart: "Re: [C] parsing command line switches"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 26 Jan 2004 20:08:24 GMT
I haven't found any examples of code that parses command line
switches. I tried this:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if(argc != 3) exit(EXIT_FAILURE);
if(strcmp(argv[2], "-s") == 0)
printf("do s\n");
else if(strcmp(argv[2], "-t") == 0)
printf("do t\n");
else
{
fprintf(stderr, "invalid switch\n");
exit(EXIT_FAILURE);
}
return 0;
}
and it works, but I was wondering if this is anything like the
conventional method.
Marlene
- Next message: Josh Sebastian: "Re: open file with arbitrary name"
- Previous message: cald: "Derived Class from a base class..."
- Next in thread: Robert W Hand: "Re: [C] parsing command line switches"
- Reply: Robert W Hand: "Re: [C] parsing command line switches"
- Reply: Jason: "Re: [C] parsing command line switches"
- Reply: Arthur J. O'Dwyer: "Re: [C] parsing command line switches"
- Reply: Martijn Lievaart: "Re: [C] parsing command line switches"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|