Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int checkChar(char);
  4. int checkBin(char);
  5. int move (char);
  6.  
  7. int main (void){
  8.   int stato = 0;
  9.   char c;
  10.   while ((c=getchar())!='\n'){
  11.     stato=move(c);
  12.     if (stato==1){
  13.       break;
  14.     }
  15.   }
  16.  
  17.   if (stato==0){
  18.     printf("Stringa APPARTENENTE al linguaggio\n");
  19.   } else {
  20.     printf("Stringa NON appartentene al linguaggio\n");
  21.   }
  22.   return 0;
  23. }
  24.  
  25. int move (char c){
  26.   if (checkChar(c) || checkBin(c)){ //Se una delle due funzini è true
  27.     return 0;                       //Resta nello stato
  28.   }
  29.   return 1;                         //Cambia stato
  30. }
  31.  
  32. int checkChar(char c){
  33.   if (c<'a' || c>'z'){
  34.     return 0;  //0 è interpretato come false in c
  35.   }
  36.   return 1;
  37. }
  38.  
  39. int checkBin(char c){
  40.   if (c!='0' && c!='1'){
  41.     return 0;  //0 è interpretato come false in c
  42.   }
  43.   return 1;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement