首页 > 代码库 > C和指针c6-1

C和指针c6-1

#include<stdio.h>#include<stdlib.h>char *find_char(char const *source_str, char const *desc_str);int main(void){    char *source_str = "ABCDEF";    char *desc_str = "MMD";        char *c = find_char(source_str, desc_str);    if(c != NULL)    {        printf("%c\n", *c);    }    else    {        printf("IS NULL!\n");        }            return EXIT_SUCCESS;}char *find_char(char const *source_str, char const *desc_str){    if( (source_str == NULL) || (desc_str == NULL) )    {        return NULL;    }        int i = 0;    while(*desc_str != \0)    {        while(*source_str != \0)        {            if(*desc_str == *source_str)            {                char c = *source_str;                char *d = &c;                return d;            }            source_str++;            i++;        }        desc_str++;        source_str -= i;//将source_str的指针置位         i = 0;    }        return NULL;}