Solved

Error in using strcasestr() in MS Visual C++

Posted on 2016-10-25
2
41 Views
Last Modified: 2016-11-28
Hello,

I used strcasestr() for searching substring in a string but it gives an error even when i used non-standard function using
#define _GNU_SOURCE at the first line of my file. Can you please help?
0
Comment
Question by:Himani Pathak
2 Comments
 
LVL 33

Accepted Solution

by:
sarabande earned 500 total points
ID: 41858877
please post your code (choose CODE from comment box title and then past the code of the function that failed) and error message.

if you get a compiler error it is because strcasestr is not a standard (posix) string function.

if you get a linker error (undefined symbol), it is because the C runtime libraries coming with VC++ do not contain the strcasestr,

you better use stricmp (or _stricmp) for VC++ Compiler.

char * sz1 = "ABC";
char * sz2 = "abC";

int result = stricmp(sz1, sz2);
if (result == 0)  // equal
{

Open in new window

   

or, maybe better, use MFC CString class and function CString::CompareNoCase or CString::Collate (the latter uses the current locale).

char * sz1 = "ABC";
char * sz2 = "abC";

int result = CString(sz1).Collate(sz2);
if (result == 0)  // equal
{

Open in new window

 


Sara
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 41903905
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: sarabande (https:#a41858877)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fully specialized class template function 21 142
Getting IP address 8 89
Should CArray be used for a list of pointers in C++? 19 118
c++ syntax question 9 52
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

839 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