help command line arguments.....

how to

display "correct" if argv[1]="c"

display "wrong" if argv[1]="c123"

display "right" if argv[1]=abc or 123abc

display "error" if argv[1]=123

need help

thanks

p.s I use visual studio and sorry if the question is not very clear new to this.
What do you have so far?
i can only sort the 1st character using isalpha and isdigit after using atof

Why don't you post your code? Based on your first post, I don't know why you would need to call isalpha, isdigit or atof at all.

When you post your code, use code tags. They show up as "<>" in the Format menu. Using code tags will make it easier for us to read and comment on your code.
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <errno.h> 

using namespace std;

const double MAXRANGE = 32000;
const double MINRANGE = -32000;


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

{
// err 1 - If the number of parameters is 1 then the program MUST print  ID string .
	if (argc == 1)  
      {
	   cout << "3423390" << endl ;
       return 0 ; 
      }

    
/* err 1-   If the number of parameters is 2 the output shall be 'P' which signals a Parameter error
               If the number of parameters is more than 3, the output shall be 'P'.*/
    if(argc==2 || argc>=4) 
      {
	   cout<<"P"<<endl;
	   return 0;
      }
   
	if(argc==3)
      {
		     
	   int num1=atol(argv[1]);
       int num2=atol(argv[2]);
	   int result=(num1+num2);

	   
{
 

	
/*err-3 All input numbers must be between (and including) +32000 or -32000, but
      excluding Zero*/ 

/*err-3 If any operands are not valid decimal numbers the output shall be 'X'.
            NB: 1.3 is valid, ABC123 is not valid, 1.3.4 is not valid, 123abc is not valid.
            Using a comma separator: 1,000.9 is commonly considered valid
            (but remember: atof() will read this as '1' not as 1000.9 ).
            Scientific format is usually considered valid e.g. 1.23e2
            These input values will be tested for*/
	

	{if ((isalpha(*argv[1]))||(isalpha(*argv[2])))
	cout<<"X"<<endl;
	
	else if ((isdigit(*argv[1]))||(isalpha(*argv[2]))) 
		
		      if((num1>32000)||(num1<-32000)||(num2>32000)||(num2<-32000)||(num2==0)||(num1==0))
              cout<<"R"<<endl;
	  
	              else
		          cout<<result<<endl;
	              return 0;}

}

	}
}
Try using strtod (http://www.cplusplus.com/reference/cstdlib/strtod/). This will give you your floating point value, and you can use endPtr to determine if there are extra values after the last character that you converted. (endPtr - str should equal strlen(str))

Strtod also handle scientific notation, too, so you should be all set.
Topic archived. No new replies allowed.