Solved

'const char *' to 'char *'

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 72
Task manager indicates my c++ program memory consumption is growing? 12 111
c++ syntax question 9 48
Precision Problem in C++ 7 32
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

770 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