Solved

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

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c++ syntax question 9 66
Embarcadero C++ Builder XE10.1 Berlin red arrow Indicator 2 96
Copy output image from TWindowsMediaPlayer 6 68
Bitwise and to sum elements 2 52
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

734 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