[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

'const char *' to 'char *'

Posted on 2012-03-15
5
Medium Priority
?
608 Views
Last Modified: 2012-03-16
Hi Experts,


 char* pszFind = strstr(CStr()+uStartIndex, pSzSearch);

I got the following error :

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

I need help tp resolve this problem ?

Thanks,
0
Comment
Question by:bachra04
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 37726703
I don't knw which of the parameters the compiler complains about (since all input parameters to 'strstr()' usually are 'const char*'), but maybe a 'const_cast<char*>()' can help, see http://www.cprogramming.com/reference/typecasting/constcast.html
0
 
LVL 36

Expert Comment

by:mccarl
ID: 37727347
I don't think the problem is with what strstr is expecting, I think the issue is just with the part...

CStr()+uStartIndex

Open in new window


What are you trying to achieve with this? It doesn't really make sense.
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 37727365
Try changing that to :

const char* pszFind = strstr(CStr()+uStartIndex, pSzSearch);

Open in new window

0
 
LVL 2

Author Comment

by:bachra04
ID: 37727394
Hi infinity08,

Yes it compiles like you suggested, I just have one question is :

this is the rest of the code , is that safe to convert it to const char* :

 if (pszFind != NULL)
    {
        uIndex = pszFind - CStr();
    }
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 37727449
If uIndex is a const char*, that should be ok, yes.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question