Originally Posted by
tabstop
If result_from_strstr is a pointer to the middle of the array, and row_n is a pointer to the beginning of the array, then result_from_strstr - row_n tells you the index of that pointer in the array.
First of all, thanks for the idea! I have a serious problem. This is the code I've written:
Code:
int i, row;
void *index;
char *row_n, *result, word[15], keystrokes[20][81];
printf("Word to find: ");
fgets(word, sizeof(word), stdin);
for (i=0;i<20;i++) /* 20 lines */
{
row_n=keystrokes[i];
if ((result=strstr(keystrokes[i],word))!=NULL) /* keystrokes[i]=&keystrokes[i][0] */
{
index=result-row_n;
row=i;
gotoxy(index,row);
}
else
{
printf("There's No Such Word");
}
}
My program crashes when I run this code. Is the code properly written? How can I find the index of that pointer in the array and what about the gotoxy(col,row) function?