home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tyc
/
list17_9.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-16
|
610b
|
28 lines
/* Searching for a single character with strchr(). */
#include <stdio.h>
#include <string.h>
main()
{
char *loc, buf[80];
int ch;
/* Input the string and the character. */
printf("Enter the string to be searched: ");
gets(buf);
printf("Enter the character to search for: ");
ch = getchar();
/* Perform the search. */
loc = strchr(buf, ch);
if ( loc == NULL )
printf("The character %c was not found.", ch);
else
printf("The character %c was found at position %d.",
ch, loc-buf);
}