Solved

'const char *' to 'char *'

Posted on 2012-03-15
5
576 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Industry Leaders: 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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

691 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