Advertisement
Wander29

Untitled

Oct 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4.  
  5. bool leggi_seq();
  6. void fflush_stdin();
  7.  
  8. int main()
  9. {
  10.     for (int i = 0; i < 3; i ++)
  11.     {
  12.         printf( ( leggi_seq() && !feof(stdin)) ? "palindrome\n" : "non palindrome\n");
  13.         fflush_stdin();
  14.     }
  15. }
  16.  
  17. bool leggi_seq()
  18. {
  19.     char c;
  20.     scanf("%1c", &c);
  21.  
  22.     if ( c == '*' )
  23.         return true;    
  24.    
  25.     if ( !leggi_seq() )
  26.         return false;
  27.    
  28.     if (getchar() == c)
  29.         return true;
  30.     else
  31.         return false;
  32. }
  33.  
  34. void fflush_stdin()
  35. {
  36.     char c;
  37.     while ( (c = getchar()) != EOF && c != '\n');
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement