scanf does not stop in a loop

0
int main(){
char texto[1000];
do{ 
    scanf("%[^\n]", texto);
    if(!fakeEquals(texto)){
        if(palindromo(texto)){
            printf("SIM\n");
        }else{
            printf("NAO\n");
        }
    }
}while(!fakeEquals(texto));

return 0;

Is a program that returns whether a String is palindrome or not, when scan ("% s", text) was used; was working, but as I need to read spaces too, I switched to scanf ("% [^ \ n]", text); but when I type any word it keeps returning to me YES or NOT infinitely ...

    
asked by anonymous 19.08.2018 / 17:54

1 answer

2

Just put a space in scanf(" %[^\n]", texto); because you need to clear the buffer before reading it again, because otherwise it reads once and then never reads the other word

    
19.08.2018 / 18:07