Solved

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

Posted on 2016-10-25
2
11 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 32

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 13

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

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

746 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

14 Experts available now in Live!

Get 1:1 Help Now