1. 程式人生 > >c程式設計語言 2-4 2-5

c程式設計語言 2-4 2-5

第五彈!

第五彈!第五彈!

#include <stdio.h>

#define max 1000

void InputSpring(char s[]);
//void mySqueeze(char s1[],char s2[]);
void any(char s1[],char s2[]);

void main()
{   
    char S1[max],S2[max];
    InputSpring(S1);
    InputSpring(S2);
   // mySqueeze(S1,S2);
    any(S1,S2);
    printf("%s\n"
,S1); } void InputSpring(char s[]) { int i; int c; for(i = 0; (c = getchar())!=EOF && c!='\n' && i<max; i++) { s[i] = c; } if(c == '\n') { s[i++] = '\0'; } } /**************************** * Remark: * s1 and s2 are String format. * so the position of the '\0' * has been changing when runing * the FOR. ****************************/
void mySqueeze(char s1[],char s2[]) { int i,j,k; for(i = 0; s2[i]!='\0'&& i<=max; i++) { for(j = k = 0; s1[j]!='\0'&& j<=max; j++) { if(s1[j] != s2[i]) { s1[k++] = s1[j]; } } s1[k] = '\0'
; } } void any(char s1[],char s2[]) { int i,j; for(i = 0; s2[i]!='\0'&& i<=max; i++) { for(j = 0; s1[j]!='\0'&& j<=max; j++) { if(s1[j] == s2[i]) { s1[j] = '\0'; } } } }