Solved

'const char *' to 'char *'

Posted on 2012-03-15
5
544 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 35

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 500 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now