从第一个字符串中删除第二个字符串中出现过的所有字符

时间:2014-07-24 09:58:23   收藏:0   阅读:163
// 从第一个字符串中删除第二个字符串中出现过的所有字符

#include <stdio.h>

char* remove_second_from_first( char *first, char *second )
{
    if( first == NULL || second == NULL )
    {
        printf("first or/and second should not be NULL\n");
        return NULL;
    }

    char flag[256]={0};
    char *p, *q;

    p = second;
    while( *p != \0 )
        flag[*p++] = 1;

    p = q = first;
    while( *q != \0 )
    {
        if( flag[*q] == 1 )
        {
            q++;
            continue;
        }
        *p++ = *q++;
    }
    *p = \0;

    return first;
}

int main(void)
{
    char s1[101], s2[101];
    scanf("%s",s1);
    scanf("%s",s2);
    char *result = remove_second_from_first(s1,s2);
    printf("%s\n",result);

    return 0;
}

 

bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣

从第一个字符串中删除第二个字符串中出现过的所有字符,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!