TODO: If a certain word exists in the .txt file, copy that word to another txt file
PROBLEM: It won't write the word after it is found in "from.txt" to "to.txt".
ERROR:
This line: while ((fscanf(ifp, "%s", line)) != EOF)
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define MAX_LINE 256
void main()
{
    FILE *ifp;
    FILE *ofp;
    char line[MAX_LINE];
    char word[MAX_LINE];
    if ((ifp = open("from.txt", "r")) == NULL)
    {
        printf("Can't open input file.");
        exit(1);
    }
    if ((ofp = open("to.txt", "w")) == NULL)
    {
        printf("Can't open output file.");
        exit(1);
    }
    printf("Enter your word: ");
    gets(word);
    while ((fscanf(ifp, "%s", line)) != EOF)
    {
        if (strcmp(line, word) == 0)
        {
            fputs(line, ofp);
            break;
        }
    }
    fclose(ifp);
    fclose(ofp);
    getch();
}
 
     
     
     
    