So the program should let me introduce a word, then search for the word from In.txt then put all the lines where it finds the word in Exit.txt. I have no errors but after I introduce the word I get "Can't read" from the if statement. Any ideas? Thank you very much, I am just getting started with files.
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE* fis, * fis2;
char* sir, * rez, word[50];
printf("Word: ");
gets(word);
sir = malloc(50 * sizeof(char));
fis = fopen("In.txt", "rt");
if (fis == NULL)
printf("Can't open file!");
else
{
while (!feof(fis))
{
rez = fgets(sir, 50, fis);
if (rez == NULL)
printf("Can't read!");
else
if (rez == word)
{
fis2 = fopen("Exit.txt", "wt");
fputs(rez, fis2);
}
}
}
fclose(fis);
free(sir);
return 0;
}