Advertisement
Guest User

Untitled

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