473,322 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

cannot convert parameter 2 from 'const char *' to 'char *'

Hi,

I'm using a third party library which has a function that expects an arg
of type const char*. I have a char* which is assigned a value at run
time - how can I pass it to my function?

Thanks

Nov 15 '05 #1
3 6250

Alfonso Morra wrote:
Hi,

I'm using a third party library which has a function that expects an arg
of type const char*. I have a char* which is assigned a value at run
time - how can I pass it to my function?

Thanks


Probably you told us the opposite. Your function expects a char*
argument and you
are passing const char* actual. Use a explicit char* cast before
passing it to the function, thats the only option you have.(Assuming
you cannot change third party library function)

--
kr******@india.ti.com

Nov 15 '05 #2

Krishanu Debnath wrote:
Alfonso Morra wrote:
Hi,

I'm using a third party library which has a function that expects an arg
of type const char*. I have a char* which is assigned a value at run
time - how can I pass it to my function?

Thanks


Probably you told us the opposite. Your function expects a char*
argument and you
are passing const char* actual. Use a explicit char* cast before
passing it to the function, thats the only option you have.(Assuming
you cannot change third party library function)

--
kr******@india.ti.com


Any decently written library should have things like when to
use const and when not to, sorted out.
What if the third party modifies the input?
Think of ...
strcpy("Hello", "World");
and you'll get my point.
Better still, copy it to some temporary buffer and pass the buffer.
Surely, some code would have been most welcome here.

Nov 15 '05 #3
Krishanu Debnath <kr**************@gmail.com> wrote:
Probably you told us the opposite. Your function expects a char*
argument and you
are passing const char* actual. Use a explicit char* cast before
passing it to the function, thats the only option you have.(Assuming
you cannot change third party library function)


That's only advisable if the const char * actually points to
modifiable memory; if it does, it might be better off not being
declared const. If it does not (for example, if it points to a string
literal), and the third party function attempts to modify the string
it is passed, tragedy is the likely result.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate...
6
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void...
3
by: kaizen | last post by:
Hi, i wrote the code in C and compiled in VC++ compiler. at that time it has thrown the below mentioned error. error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *'...
1
by: fheinstein | last post by:
Hello, I am a newbies in .NET and i am followin a tutorial to create my first MFC program but when a compile a have this problem: See the file attach! Please help Compiling......
3
by: bg_ie | last post by:
Hi, I am using a API I downloaded from the internet programmed in C. I need the function below which works with this api in my c++ file - void StoreNoteCallback(void *context, int arglen,...
1
by: asenthil | last post by:
Hai this is senthil... I had tried to write a string which fetched from a database. into a file... when i tried to compile the solution the following error occurs like this error C2664:...
2
by: nassim.bouayad.agha | last post by:
Hello, here is a code snippet showning my problem : template<typename _K> class TClass1 { public: void Process(const _K& arg) const {
5
by: slizorn | last post by:
well the error i get is the title above: error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char' error is form this line searchTree(treeObj->root ,data1.c_str());...
14
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.