匹配的话,我想匹配的两个词,然后打印出来e.g“行为”和“猫”有'一个,对它们的C”和‘T’,使他们匹配。这里是我的代码:用相同的字母
#include <stdio.h>
#include <stdlib.h>
main()
{
FILE *fptr;
char words[100], input[100], store[1000][100]
char ch
int i,j,k,z,b,*ptr;
ptr = &b;
fptr = fopen("d:\\words.txt","r");
if (fptr == NULL)
{
printf("Could not open file");
exit(1);
}
printf("Enter the scrambled word: ");
fflush(stdin);
fgets (input,sizeof(input),stdin);
i = 0;
while (fgets(words,sizeof(words),fptr) != NULL)
{
if (strlen(input) == strlen(words))
{
strcpy(store[i],words);
++i;
}
}
//this is where the problem is:
/*am trying to match the letters in two words, if they don't match then store 1 in b,
if b=0 then print out the word which matched with string 'input'*/
for(z = 0; z < 1000; ++z)
{
b = 0;
for(j = 0; j < strlen(input); ++j)
{
for(k = 0; k < strlen(store[z]); ++k)
{
if(input[j] != store[z][k])
*ptr = 1;
}
}
if(*ptr == 0)
{
printf("Word #%2d is: %s\n", z, store[z]);
}
}
fflush(stdin);
getchar();
}
请真的需要帮助。对不起,如果我没有明确表示我的问题。
你的问题是什么? – trojanfoe
你在你的代码中说“这是问题所在”,但你不会告诉我们你的问题是什么,它与你的期望有什么不同。 –