Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 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.   if (stato==0){
  17.     printf("Stringa APPARTENENTE al linguaggio\n");
  18.   } else {
  19.     printf("Stringa NON appartentene al linguaggio\n");
  20.   }
  21. }
  22.  
  23. int move (char c){
  24.   if (checkChar(c) || checkBin(c)){ //Se una delle due funzini è true
  25.     return 0;                       //Resta nello stato
  26.   }
  27.   return 1;                         //Cambia stato
  28. }
  29.  
  30. int checkChar(char c){
  31.   if (c<'a' || c>'z'){
  32.     return 0;  //0 è interpretato come false in c
  33.   }
  34.   return 1;
  35. }
  36.  
  37. int checkBin(char c){
  38.   if (c!='0' && c!='1'){
  39.     return 0;  //0 è interpretato come false in c
  40.   }
  41.   return 1;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement