我的目标是取两个字符串并比较结果,如果它们都以“ing”,“ed”结尾或者结尾不匹配。它总是说字符串不匹配。
#include <stdio.h>
#include <conio.h>
#include <string.h>
int ised(char str[]);
int ising(char str[]);
int main()
{
char str1[30],str2[30];
printf("Enter 1st string:\n");
gets(str1);
printf("Enter 2nd string:\n");
gets(str2);
if((ising(str1))||(ised(str1))||(ising(str2))||(ised(str2)))
{
if(ising(str1)&&ising(str2))
{
printf("Both strings end with ing");
}
else if(ised(str1)&&ised(str2))
{
printf("Both strings end with ed");
}
else
printf("Both strings ending do not match");
}
else
printf("One or both strings do not end with ing or ed.Program Quitting...");
getch();
return 0;
}
int ising(char str[])
{
int len,flag=0;
len=strlen(str);
if (!(strncpy(&str[len-3],"ing",3)))
flag=1;
else
flag=0;
return flag;
}
int ised(char str[])
{
int len,flag=0;
len=strlen(str);
if( !(strncpy(&str[len-2],"ed",2)) )
flag=1;
else
flag=0;
return flag;
}