Advertisement

C++ - problem with *char[]

Started by October 19, 2000 05:35 PM
3 comments, last by origil 24 years, 2 months ago
void main(int argc, *argv[]) { if(argv[2]==''q'') } The problem here was that I couldn''t convert the *char to an int nor to char type. When I tried: if(*argv[2]==''q'') the program was compiled but when program crashed at execution. I''d like to know how to use or store the seperate values in the array. For example: char a = argv[2];
The Department of Next Life - Get your Next-Life Insurance here!
char a = argv[2][0];
char a = *argv[2];

so:


void main(int argc, *argv[])
{
if(*argv[2]==''q'')
...
}


will work, but I will bet you money that argc < 3 when it crashed on you.
Advertisement
Thanks, but the program still crashes.
Argc was larger than 3 when it did.

#include

using namespace std;

void main(int argc,char *argv[])
{
if(*argv[2]==''q''){cout<<"argv[2] is q";}
}

It says the program has performed an illegal operation.
Why not just do this:
    // Stuff ...void main(int argc,char *argv[]) {  if(argv[2][0]==''q'') {    cout<< "argv[2] is q";  }}[/source]Or this:[source]// Stuff ...#include <string.h>void main(int argc,char *argv[]) {  if(strcmp(argv[2],"q")==0) {    cout<< "argv[2] is q";  }}    





Null and Void
At least I don't know COBOL...
Ok, thanks .
The Department of Next Life - Get your Next-Life Insurance here!

This topic is closed to new replies.

Advertisement