LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-06-2004, 12:40 PM   #1
ashirazi
Member
 
Registered: Jul 2004
Posts: 60

Rep: Reputation: 15
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]);
}
}
}
 
Old 08-06-2004, 12:51 PM   #2
ashirazi
Member
 
Registered: Jul 2004
Posts: 60

Original Poster
Rep: Reputation: 15
I forgot to mention, I get the error whereever argv is used
 
Old 08-06-2004, 02:07 PM   #3
Charalambos
Member
 
Registered: Aug 2004
Location: Switzerland
Distribution: debian
Posts: 149

Rep: Reputation: 15
What type has the variable xflag? And where is it declared?
 
Old 08-06-2004, 04:58 PM   #4
ashirazi
Member
 
Registered: Jul 2004
Posts: 60

Original Poster
Rep: Reputation: 15
sorry about that, thats passed as int. I just realized that
 
Old 08-06-2004, 05:02 PM   #5
Charalambos
Member
 
Registered: Aug 2004
Location: Switzerland
Distribution: debian
Posts: 149

Rep: Reputation: 15
Quote:
"Cannot convert 'int' to 'const char' " error
In whick line does that error occur?
 
Old 08-06-2004, 09:58 PM   #6
aiza
LQ Newbie
 
Registered: Jul 2004
Posts: 18

Rep: Reputation: 0
Re: c++ ERROR: int to const char

Quote:
Originally posted by ashirazi
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 think you missed '*' sign before 'argv[]' in function definition. It should be:
inline void read_args(int argc, char *argv[], int &ns, int *which_hill)
{
......
}
 
Old 08-06-2004, 10:01 PM   #7
ashirazi
Member
 
Registered: Jul 2004
Posts: 60

Original Poster
Rep: Reputation: 15
Thanks man I fixed it. I wasnt passing the arry right.

Thanks a lot anyway
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++: #define OR const int ? Hady Programming 5 10-07-2005 11:43 AM
char to int: a twist Guru3 Programming 5 12-05-2004 08:49 AM
global const int X = DEFINED (shows value in debugger?) abs Programming 2 09-25-2004 11:09 AM
invalid conversion from `char' to `const char* bru Programming 6 05-09-2004 03:07 PM
int(char(254)) becomes kalleanka Programming 2 02-17-2004 03:35 PM


All times are GMT -5. The time now is 02:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration