I'm trying read a txt using fgets... I want to compare two strings and print them, but I can change of line...How can I change of line? I want to find some words in my txt. Please, help me!
Here is my code:
#include<stdio.h>
#include<string.h>
FILE *arquivo;
char string1[5],string2[5];
int main()
{
int t=0;
int nada;
arquivo=fopen("arquivo.txt", "r");
if(arquivo==NULL) perror("Erro ao abrir o arquivo");
gets(string2);
do
{
fgets(string1,5,arquivo);
if(strcmp(string1,string2)!=0)
{
puts(string1);
}
fseek(arquivo, -3,SEEK_CUR);
t+=1;
}
while(t<5); // I put this while because the next is not working...
//while(string1[4]!=EOF);// This while is not working...
fclose(arquivo);
printf("\n Aperte uma tecla para sair \n\n");
scanf("%f",&nada);
I'm a beginner at programming but to I also had to compare strings and I just used a getline and a simple if statement to compare them but this section on this page might help you find certain strings.