Invalid Conversion From Const Char To Char Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack invalid conversion from 'const char*' to 'char' -fpermissive arduino Overflow the company Business Learn more about hiring developers or posting ads with us invalid conversion from ‘char*’ to ‘char*’ Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a invalid conversion from const char to char fpermissive community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up invalid conversion from 'const char*' to 'char*' up vote 20 down vote favorite 3 Have invalid conversion from ‘const char*’ to ‘char*’ c_str a code as shown below. I have problem passing the arguments. stringstream data; char *addr=NULL; strcpy(addr,retstring().c_str()); retstring() is a function that returns a string. //more code printfunc(num,addr,data.str().c_str()); I get the error invalid conversion from 'const char*' to 'char*' . initializing argument 3 of 'void Printfunc(int, char*, char*)'on argument 3 of the function on the above line. The function is called as shown below void Printfunc(int a,char *loc, char *stream) please let
Invalid Conversion From Const Char * To Int
me know if I need to change any initialization. c++ share|improve this question asked Jan 7 '14 at 23:34 user2333234 110116 2 Compiler wants you to change char *stream to const char *stream –marcinj Jan 7 '14 at 23:37 The answers below deal with the compilation error but you will also need to allocated some memory for the destination buffer passed to strcpy - you cant just past a NULL pointer as the destination argument –mathematician1975 Jan 7 '14 at 23:40 1 Calling data.str().c_str() is likely to have surprising results. –Chad Jan 7 '14 at 23:49 add a comment| 3 Answers 3 active oldest votes up vote 22 down vote accepted Well, data.str().c_str() yields a char const* but your function Printfunc() wants to have char*s. Based on the name, it doesn't change the arguments but merely prints them and/or uses them to name a file, in which case you should probably fix your declaration to be void Printfunc(int a, char const* loc, char const* stream) The alternative might be to turn the char const* into a char* but fixing the declaration is preferable: Printfunc(num, addr, const_cast
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more
Convert Const Char* To Char* C++
about Stack Overflow the company Business Learn more about hiring developers or posting ads copy const char* to char* with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow const_cast
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers http://stackoverflow.com/questions/32831819/c-invalid-conversion-from-const-char-to-char or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only http://forum.arduino.cc/index.php?topic=335810.0 takes a minute: Sign up C++ invalid conversion from 'const char*' to 'char' up vote 0 down vote favorite I'm new to Arduino and C++. I wanted to make a program which will read input from a serial port. However const char there seem to be some problems when I try to compile it. The error message that I am receiving is: invalid conversion from 'const char*' to 'char' Here is my code: #define nombreBouteille 10 #define nombreCocktail 8 String cocktail[nombreCocktail][nombreBouteille][2]; String bouteille[nombreBouteille]; int serialValue; void loop() { if (Serial.available() > 0) int serialValue = Serial.read(); if (serialValue == '1') { readBouteille(); readCocktail(); } } //Read and set the bottles content void readBouteille() { for( int i = 0; i < nombreBouteille; invalid conversion from i++) { bouteille[i] = Serial.readStringUntil(" "); } } //Read the cocktail void readCocktail() { for( int i = 0; i < nombreCocktail; i++) { for ( int j = 0; j < nombreBouteille; j++) { cocktail[i][j][0] = Serial.readStringUntil(" "); cocktail[i][j][1] = Serial.parseInt(); } } } c++ arduino share|improve this question edited Sep 28 '15 at 21:18 Paul R 148k16224367 asked Sep 28 '15 at 21:04 Sarah Gln 111 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote readStringUntil takes a single char parameter to specify a delimiter, not a C string (char *). So change: bouteille[i] = Serial.readStringUntil(" "); // wrong: " " is a `char *` to: bouteille[i] = Serial.readStringUntil(' '); // right: ' ' is a `char` and similarly for the other call to readStringUntil. share|improve this answer edited Sep 28 '15 at 21:18 answered Sep 28 '15 at 21:13 Paul R 148k16224367 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged c++ arduino or ask your own question. asked 1 year ago viewed 2989 times active 1 year ago Blog Stack Overflow Podcast #91
> Programming Questions > error: invalid conversion from 'const char*' to 'char' [-fpermissive] Print Go Down Pages: [1] Topic: error: invalid conversion from 'const char*' to 'char' [-fpermissive](Read 1 time) previous topic - next topic rremm2000 Newbie Posts: 35 Karma: 1[add] error: invalid conversion from 'const char*' to 'char' [-fpermissive] Jul 14, 2015, 01:48 am I've made a few global vars / constants to handle serial port input, ran into this errorjunk.ino: In function 'void loop()':junk.ino:35:13: error: invalid conversion from 'const char*' to 'char' [-fpermissive]Error compiling.I didn't declare this as a const char, just char so I could put new char data into it but, this error is got me confused?Code: [Select]
bool serControl = false;
int serIntIn = 0;
char serCharIn ="";
String serStringIn = "";
const int SER_RET_INT = 1;
const int SER_RET_CHAR = 2;
const int SER_RET_STRING = 3;
void setup()
{
Serial.begin(19200); // opens serial port, sets data rate to 9600 bps
//attachInterrupt(1, intCnt, RISING ); // syntax attachInterrupt(interrupt, ISR, mode)
//interrupts();
//tickEvent = t.every(2000, intCnt); //doFreeRun is controlled by timer
}
void loop() {
serIntIn = 0;
serCharIn = "";
serStringIn = "";
}
-------------It's a fool looks for anything other than blood in chambers of the human heart, for both passion and logic emanate from the human mind. LarryD Tesla Member Posts: 9,408 Karma: 954[add] The last thing you did is where you should start looking. Re: error: invalid conversion from 'const char*' to 'char' [-fpermissive] #1 Jul 14, 2015, 02:03 am Last Edit: Jul 14, 2015, 02:04 am by LarryD Using "const" prevents you from changing the variable in code.Remove const from variables you change.Edit, my mistake. No technical PMs.The last thing you did is where you should start looking. rremm2000 Newbie Posts: 35 Karma: 1[add] Re: error: invalid conversion from 'const char*' to 'char' [-fpermissive] #2 Jul 14, 2015, 02:11 am Hopefully the "edit my mistake" was y