Solved

strstr

Posted on 2001-06-15
5
756 Views
Last Modified: 2008-02-26
could you guys explain what does strstr function do?
thanks
0
Comment
Question by:zunera
[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
  • 3
5 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 6196524
char *strstr(const char *string, const char *strCharSet)

The strstr function returns a pointer to the first occurrence of strCharSet in string.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6196525
Example

/* STRSTR.C */

#include <string.h>
#include <stdio.h>

char str[] =    "lazy";
char string[] = "The quick brown dog jumps over the lazy fox";
char fmt1[] =   "         1         2         3         4         5";
char fmt2[] =   "12345678901234567890123456789012345678901234567890";

void main( void )
{
   char *pdest;
   int  result;
   printf( "String to be searched:\n\t%s\n", string );
   printf( "\t%s\n\t%s\n\n", fmt1, fmt2 );
   pdest = strstr( string, str );
   result = pdest - string + 1;
   if( pdest != NULL )
      printf( "%s found at position %d\n\n", str, result );
   else
      printf( "%s not found\n", str );
}


Output

String to be searched:
   The quick brown dog jumps over the lazy fox
            1         2         3         4         5
   12345678901234567890123456789012345678901234567890

lazy found at position 36

0
 
LVL 32

Accepted Solution

by:
jhance earned 20 total points
ID: 6196528
strstr locates a SUBSTRING within another string.

Let's say you have:

char *str1 = "This is only a test";
char *p;

and you do:

p = strstr(str1, "only");

p will point to the "o" in only.  If, however, you did:

p = strstr(str1, "ONLY");

p will be NULL since the string "ONLY" does not appear in the string str1.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6196534
I just copied and pasted this from MSN help document.
See following link for more info.
http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_crt_strstr.2c_.wcsstr.2c_._mbsstr.htm
0
 

Author Comment

by:zunera
ID: 6196612
Answer is very simple and clear, great thanks
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
Excel/Word Add-in in what language? 5 163
AVI wait icons for CAnimateCtrl in Visual Studio 2008 MFC 1 172
Dialogbox API leak? 18 118
No module found pypyodbc, 3 58
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 clear a vector as well as how to detect empty vectors in C++.

738 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