Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int checkChar(char);
- int checkBin(char);
- int move (char);
- int main (void){
- int stato = 0;
- char c;
- while ((c=getchar())!='\n'){
- stato=move(c);
- if (stato==1){
- break;
- }
- }
- if (stato==0){
- printf("Stringa APPARTENENTE al linguaggio\n");
- } else {
- printf("Stringa NON appartentene al linguaggio\n");
- }
- return 0;
- }
- int move (char c){
- if (checkChar(c) || checkBin(c)){ //Se una delle due funzini è true
- return 0; //Resta nello stato
- }
- return 1; //Cambia stato
- }
- int checkChar(char c){
- if (c<'a' || c>'z'){
- return 0; //0 è interpretato come false in c
- }
- return 1;
- }
- int checkBin(char c){
- if (c!='0' && c!='1'){
- return 0; //0 è interpretato come false in c
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement