Searching a character in the given string using strchr() C function
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows 2003 Server Standard Edition
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info:
To do: Searching a character in the given string using strchr() C function
To show: Using strchr() C function to find a character in the given string
// Using strchr()/wcschr()/_mbschr()
#include <stdio.h>
#include <string.h>
int main(void)
{
char *string = "This is a test statement, testing! ";
char character1 = 'e', character2 = 'z';
printf(" Using strchr()\n");
printf(" --------------\n");
if (strchr(string, character1) != NULL)
printf("\'%c\' was found in \"%s\".\n", character1, string);
else
printf("\'%c\' was not found in \"%s\".\n", character1, string);
if(strchr(string, character2) != NULL)
printf("\'%c\' was found in \"%s\".\n", character2, string);
else
printf("\'%c\' was not found in \"%s\".\n", character2, string);
return 0;
}
Output example:
Using strchr()
--------------
'e' was found in "This is a test statement, testing! ".
'z' was not found in "This is a test statement, testing! ".
Press any key to continue . . .