c++ ERROR: int to const char
Hey guys,
Thanks a lot for all the replies for the previous posts. I get a "Cannot convert 'int' to 'const char' " error, when i try to implement this inline function. My main() just has the following declarations: int ns, int* which_hill, and argv[] is an array of the parameters to call main(). The following is the function. Thanks a million guys Aga inline void read_args(int argc, char argv[], int &ns, int *which_hill) { /* Check if only specified partitions are to be processed. */ for (int i=0; i<argc; i++) { if (strcmp(argv[i],"-x") == 0) { xflag = 1; /* Check the next arguement to see the number of partitions we will process. */ if (i+1 >= argc) { cout << "\nERROR: Number of partitions not specified with -x option"; exit(0); } i++; ns = (int)atoi(argv[i]); if (i+ns >= argc) { cout << "\nERROR: Number of given partitions does not match specification with -x option"; exit(0); } /* Allocate an array indexing partition numbers processed */ if ( (which_hill = (int *)malloc(ns*sizeof(int))) == NULL) { cout << "\nERROR: Memory allocation problem\n"; exit(0); } /* Read in successive arguements until we fill up the partition array. */ for (int k=0; k< ns; ++k) { i++; which_hill[k] = (int)atoi(argv[i]); } } } |
I forgot to mention, I get the error whereever argv is used
|
What type has the variable xflag? And where is it declared?
|
sorry about that, thats passed as int. I just realized that
|
Quote:
|
Re: c++ ERROR: int to const char
Quote:
inline void read_args(int argc, char *argv[], int &ns, int *which_hill) { ...... } |
Thanks man I fixed it. I wasnt passing the arry right.
Thanks a lot anyway |
All times are GMT -5. The time now is 02:20 AM. |