1
I have a string that receives a keyboard input value and a file that contains a string. What I need to do is compare the typed string with the file string and check if they are the same, but I went to see what kind of string the file was taking and it was coming with strange characters (play button, '@' and down arrow). The code in thesis seems to work, however I would like to know why the string I’m bringing to compare with the one typed by the user is coming with these 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;
}
What’s in the file?
– Maniero
The file has the name "Lucas", IE, when the user type string on the keyboard, is to make a comparison. However, when I pull this string out of the file to see what’s going on, some strange characters come out. Then the program always says "Not Found". I already checked and the file is with ANSI text and still did not help.
– user103375