I have a string that receives an input value from the keyboard and a file that contains a string. What I need to do is compare the string typed with the file string and see if they are the same, but I went to see what kind of string the file was taking and was coming with strange characters (play button, '@' and down arrow) . The thesis code seems to work, however I'd like to know why the string I'm bringing to compare with the string entered by the user is coming with those characters.
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <string.h>
main()
{
setlocale(LC_ALL,"portuguese");
FILE *arquivo;
char frase[6];
char frase2[6];
int i;
if(arquivo = fopen("teste.txt", "r") == NULL)
{
puts("ERRO! IMPOSSÍVEL ABRIR O ARQUIVO");
}
else
{
printf("Digite a frase: \n");
gets(frase);
fgets(frase2, 6, arquivo);
puts(frase2);
if(i = strcmp(frase, frase2) == 0)
{
puts("Encontrado");
}
else
{
puts("Não encontrado");
}
}
fclose(arquivo);
getch();
return 0;
}