NEED HELP WITH THIS PART OF CODE

#include <cstdlib>
#include <iostream>
#include <string.h>
#include <cmath>
using namespace std;

int main(int argc, char *argv[])
{
if(argc==1)
{ cout << "P" << endl;}

if(argc==2)
{cout << "P" << endl;}

if(argc==3)
{cout << "P" <<endl;}

if(argc >4)
{cout << "P" << endl;}

if(argc==4)

for( int i= 1 ; i < argc; i++)
{ string validnumber(" ");
int decCount(0);

for( int j = 0; j <strlen(argv[i]) ; j++)
{
char ch == (argv[i][j]); //<<--------- SEEN AS UNDECLARED ??

if(ch=="0"|ch=="1"|ch=="2"|ch=="3"|ch=="4"|ch=="5"|ch=="6"|ch=="7"|ch=="8"|ch=="9")
{
if( ch == ".")
{ decCount ++;
(decCount > 1)
{cout << "X" <<endl;}
}
{ validnumber = valid + ch;}
else {cout << "X" << endl;}



system ("PAUSE") ;
return 0 ;


}}}}
Last edited on
Is that meant to be = instead of == ?

== is testing if its the same.
if you wil test if 10 is equal to 10 you write

10==10

now the program reads it's equal.

10==11

than it wil read it's not equal.
10!=42 tests if it's not equal
10<19 tests if 19 is bigger than 10
15>16 tests if 15 is greater than 16
15<=19 tests if 15 is greater or equal to 19
10>=9 tests if 10 is equal or greater to 9

you can forexample us that wit a if statment


1
2
3
4
5
6
7
8
9
int x = 10;    // x is 10

if(x==10){   // x is equal to 10, this test is true 
cout << "this gets printed if x is equal to 10" << endl;
}

if(x<=5){     //x is greater than 5, this test is false
cout << "wil this be printed on the screen??" << endl;
}


i hope this is a good anser to your question ;)
What Moschops refers to is the following line:

char ch == (argv[i][j]); //<<--------- SEEN AS UNDECLARED ??

The comparison operator doesn't make sense there
char ch == (argv[i][j]); //<<--------- SEEN AS UNDECLARED ??

Its because in

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

argv is decleared as a single dimentional array, not a two dimetional array, argv[][] refers to a two dimetional array.
closed account (o1vk4iN6)
1
2
3
4
5
char **argv;

char *argv[];

char argv[][];


All the above declarations are acceced the same way (note: syntax). An array is just a pointer after all.
Last edited on
I would like to differ

1
2
3
4
5
char **argv;  // argv = pointer(pointer(char))

char *argv[];  // argv = pointer(pointer const(char))

char argv[][];  // argv =  pointer const(pointer const(char)) 
Topic archived. No new replies allowed.