File: cmdline.C

package info (click to toggle)
librudiments0 0.27-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,528 kB
  • ctags: 2,284
  • sloc: cpp: 14,657; sh: 7,547; ansic: 2,664; makefile: 945; xml: 15
file content (28 lines) | stat: -rw-r--r-- 786 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright (c) 2001  David Muse
// See the file COPYING for more information

#include <rudiments/commandline.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, const char **argv) {

	commandline     cmdline(argc,argv);

	// if -help was specified, display a usage message
	if (cmdline.found("-help")) {
		printf("usage:  divide -divisor number -dividend number\n");
		exit(0);
	}

	// If -divisor and -dividend are supplied, use them.  Otherwise
	// display an error message.
	if (cmdline.found("-divisor") && cmdline.found("-dividend")) {
		double	divisor=atof(cmdline.value("-divisor"));
		double	dividend=atof(cmdline.value("-dividend"));
		printf("%0.2f\n",divisor/dividend);
	} else {
		printf("You must supply a divisor and a dividend.\n");
	}
}