Solved

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

Posted on 2016-10-25
2
101 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
[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
2 Comments
 
LVL 34

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

Independent Software Vendors: 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

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

726 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