Find the string of characters C language exercises

  C language exercises, in order to better grasp the pointer, I found that if realized character lookup function, you can,

This inside knowledge to design, as well as an array of characters two pointers, etc., it is worth practicing.

 1 #include <stdio.h>
 2 
 3 
 4 #define TRUE 1
 5 #define FALSE 0
 6 
 7 int find_char(char **strings, char value);
 8 
 9 char *str[] = {
10     "first",
11     "second",
12     "third"
13 };
14 
15 int main(int argc, char *argv) {
16 
17     char c;
18     scanf("%c", &c);
19     if (find_char(str,c))
20     {
21         printf("%c in sourcestr\n", c);
22     }
23     else {
24         printf("%c not sourcestr\n", c);
25     }
26     
27 }
28 
29 
30 int find_char(char **strings, char value) {
31     char *string;
32     while ((string=*strings++)!=NULL)
33     {
34         while (*string!= '\0') {
35             if (*string++ == value) {
36                 return TRUE;
37             }
38         }
39     }
40     return FALSE;
41 }

On VS2015 program runs as follows:

Guess you like

Origin www.cnblogs.com/xuelanga000/p/11308076.html