C Tutorial – Searching for Strings in a Text File

In this C language tutorial we will show you how to search for a string in a text files. We will make use of command-line input, fopen or fopen_c and system to clear the screen. Make sure that you have read and understand the following tutorial C tutorial File I/O using Text Files before you continue this one. Add the end of the tutorial you can download the source code of this tutorial.

We start this C language tutorial with some include statements. To make use of strings in your program you need to make sure that you include the header file string.h
More »


Posted in C Tutorials | 13 Comments


C Reference String Operation: strstr()

The function strstr() returns a pointer to the first occurrence of x in a string.
It is also know as searching for a sub-string in a string.

Usage:

char * strstr ( const char *, const char * );
char * strstr ( char * str1, const char * str2 );

Return Value

A pointer to the first occurrence in str1 of any of the entire sequence of characters specified in str2. If nothing is found a null pointer is returned if the sequence is not present in str1.
More »


Posted in C Reference string.h Functions | Comments Off on C Reference String Operation: strstr()