一切编译都是通过的,但是判断的时候输出的都是“The words are not anagram”

来源:互联网 发布:mac电脑壁纸摄影师 编辑:程序博客网 时间:2024/06/03 06:06

判断输入的两个单词是否为变位单词,就两个单词组成的成分都相同 

#include<stdio.h>#include<ctype.h>#include <string.h>#define SIZE  81void order_frist(char frist[],int) ;void order_second(char second[],int n );int main(void){    int i=0 , j = 0, k  ;    int I , J ; //记录两个数组的实际长度    char frist[SIZE];    char second[SIZE];    char ch  ;    printf("Enter frist word :");   while((ch = getchar ()) != '\n') //输入第一个单词存于数组first    {            frist[i] = ch ;            i ++ ;    }     printf("Enter second word :");    while((ch = getchar ()) != '\n')//输入第二个单词存于数组second    {            second[j] = ch ;            j ++ ;    }      I = strlen(frist);     J = strlen(second) ;    if(I == J)    {            void order_first( first , i) ;            void order_second( second ,j );//调用函数            for(k = 0 ; k < I ; k++)            {                if(frist[k] != second[k])//判断是否为变位单词                    break ;                                 }            if(frist[k] != second[k])                printf("The words are not anagrams.\n");            else                printf("The words are  anagrams.\n");              }    else         printf("The words are not anagrams.\n");    return 0 ;}void order_first(char frist[] ,int n ) //对第一个数组进行内部排序{    int i ,j ;    char temp ;    for (i=0; i<n-1; i++)     {            for(j = 0 ; i < n ; i++)        {            if(frist[j] < frist[i] )            {                temp = frist[i];                               frist[i] = frist[i];                 frist[j] = temp;            }        }        }    }void order_second(char second[] ,int n )//对第二个数组进行内部排序{    int i,j ;    char temp ;for (i=0; i<n-1; i++)     {          for(j = i+1 ; j < n ; j++)        {            if(second[j]<second[i])            {                temp = second[i];                               second[i] = second[j];                 second[j] = temp;            }        }     }


0 0
原创粉丝点击