Untitled
unknown
plain_text
3 years ago
814 B
0
Indexable
Never
while (fgets(buffer, 256, fp) != NULL) { i = 0; n = strlen(buffer); // the followinf loop find position of the input word in the current line and // print the position of the word on the screen // the loop basically reads each word of the file and compare it with the input word while (i < n) { // comparing current word with input word j = 0; while (i < n && j < m && buffer[i] == wrd[j]) { ++i, ++j; } // the following condition implies that the current word of buffer // is equal to input word if ((i == n || buffer[i] == ' ' || buffer[i] == '\n') && j == m) { printf("Line: %d ", line); printf("Column: %d\n", i - m); } // moving to next word while (i < n && buffer[i] != ' ') { ++i; } ++i; } ++line; }