题目 - 例题(12.8) 单词替换 C语言

1个回答

  • #include

    #include

    #include

    #define MAX 1000

    #define LEN 20

    void Input (char *a, char *b, char *c){

    gets(a);

    gets(b);

    gets(c);

    }

    void Swap (char *str, char *FindWord, char *SwapWord){

    int j,s,k,i=0,SwapWordLength,strLength,FindWordLength,n;

    char *p1,*p2;

    p1=str;

    p2=FindWord;

    strLength=strlen(str); //length of the original sentence

    FindWordLength=strlen(FindWord); //length of the old word

    SwapWordLength=strlen(SwapWord); //length of the new word

    n=SwapWordLength-FindWordLength;

    while(*p1!=' '){

    if((*p1==*p2)&&(!isalpha(*(p1-1)))) //isalpha : judge whether the char_c is an english word or not,if yes return !0,if no return 0

    while((*p1==*p2)&&(*p2!=' '))

    { p1++; p2++; i++; } //i: record how many chars has been read

    else { p1++; i++; }

    if((*p2==' ')&&(isalpha(*p1)==0)){

    //find the old word in the sentence

    if(n