argv pick up characters

trying to figure out how i can get the argv to pick up on certain characters and allocate them a function,

so to be able to get 2 numbers argv[1] and argv[2] and the third argument be 1 of 4 either parameters defined by the corresponding letters to operate the "if" commands


as i can get it to work if i assign those letters i want to corresponding numbers, but that defeats the purpose. i would like it to work with characters.


if someone could please point me in the appropriate direction would be gladly appreciated as its driving me nuts (@_@)



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
29
30
31
32
33
34
35
36
37
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <math.h>

using namespace std;

int main(int argc, char *argv[])
{

	double a1, b1;
	
	
	a1 = atof(argv[1]);
	b1 = atof(argv[2]);
	


	if (atof(argv[3]) == 'a'){
		cout << a1 + b1;
	}
	if (atof(argv[3]) == 'd'){
		cout << a1 / b1;
	}
	if (atof(argv[3]) == 's'){
		cout << a1 - b1;
	}
	if (atof(argv[3]) == 'm'){
		cout << a1 * b1;
	}
	



return 0;

}
You are trying to compare floating point number to chars.

you can access first (for example) character in given argument as usual for twodimensional arrays: argv[3][0] == 'a'
Topic archived. No new replies allowed.