《c程序设计语言》读书笔记-删除字符串中匹配的字符

#include <stdio.h>
#include <string.h>

#define Num 10

int main()
{
    int c,i,j = 0,m,n = 0,count1 = 0,count2 = 0;
    char s[Num],t[Num],st[Num],str[Num];

    printf("Please input a string:\n");

    while((c = getchar()) != EOF && c != '\n' && count1 < Num)
    {
        s[count1] = c;
        count1++;
    }

    printf("Please input another string:\n");

     while((c = getchar()) != EOF && c != '\n' && count2 < Num)
    {
        t[count2] = c;
        count2++;
    }

    for(i = 0; s[i] != '\0' && i < count1; i++)
    {
        if(s[i] != t[i])
        {
            st[j] = s[i];
            j++;
        }
    }

    for(i = 0; t[i] != '\0' && i < count2; i++)
    {
        if(s[i] != t[i])
        {
            str[n] = t[i];
            n++;
        }
    }

    for(m = 0;m < j ;m++ )
       {
           printf("%c",st[m]);
       }
       printf("\n");
    for(m = 0;m < n ;m++ )
        {
            printf("%c",str[m]);
        }
        
    return 0;
}


posted @ 2014-10-30 23:02  司空格子Ored  阅读(203)  评论(0编辑  收藏  举报