【发布时间】:2013-08-25 04:30:45
【问题描述】:
我正在尝试匹配两个单词,然后将它们打印出来,例如 'act' 和 'cat' 中包含 'a、'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();
}
我真的需要帮助。很抱歉,如果我没有把我的问题说清楚。
【问题讨论】:
-
你有什么问题?
-
您在代码中说“这就是问题所在”,但您没有告诉我们您遇到的问题是什么以及它与您的预期有何不同。
标签: c