December 2005
Beginner to intermediate
618 pages
20h 19m
English
strstr
Searches a string for a replica of another string
#include <string.h> char *strstr( const char *s1, const char *s2);
The strstr() function
searches the string s1 for the first
occurrence of the string s2 (not counting
s2’s terminating null character). The
return value is a pointer to the first character in the first
occurrence in s1 of the sequence
contained in s2, or a null pointer if
there is no such occurrence. If s2 points
to an empty string, then strstr()
returns the value of its first argument,
s1.
FILE *fpTx, *fpRx, *fpLog;
char rxbuffer[1024], *found;
/* ... */
fgets( rxbuffer, 1024, fpRx );
found =strstr( rxbuffer, "assword:" );
if ( found != NULL )
{
fputs( "Got password prompt. Sending password", fpLog );
fputs( "topsecret", fpTx );
}Read now
Unlock full access