我已經寫了一個程序來比較句子並找到相似的單詞。我應該得到的結果是每個詞的表A中的確切單元格位置相似,但我不知道該怎麼做。如何追蹤表格單元格?
#include<stdio.h>
#include<string.h>
int main()
{
int i=-1,j=0,q;
char A[1000],B[1000],C[1000][1000]={0},*x,*y;
char c[1]=" ";
// Just giving the words
printf("\nGive table A:\n");
do
{
i++;
A[i]=getchar();
}while(A[i]!='\n');
A[i]='\0';
printf("\n\nGive table B:\n");
i=-1;
do
{
i++;
B[i]=getchar();
}while(B[i]!='\n');
B[i]='\0';
// Compairing every word of the 2 tables (A and B)
y=strtok(B,c);
x=strtok(A,c);
i=0;
while(x!=NULL)
{
while(y!=NULL)
{
q=strcmp(x,y);
if(!q)
{
// I need to track the cell number of table A here but how?
printf("%s\n",x);
j++;
}
y=strtok(NULL,c);
}
x=strtok(NULL,c);
if(C[i][0])
i++;
j=0;
}
return 0;
}
所以你想比較A和B並找到A中存在於B中的單詞? –
'跟蹤細胞數量'是什麼意思? (另外:'c'應該是2個char's:一個也可以持有nul-終結符) – Kninnug
定義你的「類似」。 – moeCake