/* * logicand.c */ #include #include int lowercase(char); // prototype: takes char, returns int int digit(char); // prototype: takes char, returns int int main(void) { char cc; // declare char int words, lower, upper, num, other; // declare 5 ints words=lower=upper=num=other=0; // initialize all ints to 0 while( (cc=getchar() ) != EOF) // get character from stdin // assign to cc // evaluate: is value of cc not EOF // Ture, do block { if ( isspace(cc) ) // does cc is a space, do block { words++; // increment words continue; // go to next iteration of while loop } if ( isalpha(cc) ) // If cc contains alpha numeric value, do block { if ( lowercase(cc) ) // does cc is a lowercase, do block { lower++; // increment lower continue; // go to next iteration of while loop } else // does cc is a uppercase, do block { upper++; // increment lower continue; // go to next iteration of while loop } } if ( digit(cc) ) // if cc contains a digit, do block { num++; // increment num continue; // go to next iteration of while loop } other++; } // end while loop printf("\nThe input consisted of:\n"); printf("%d words\n", words); printf("%d lower case letters\n", lower); printf("%d upper case letters\n", upper); printf("%d digits\n", num); printf("%d miscelaneous characters\n", other); return 0; } // Functions int lowercase(char dd) { if( (dd>='a') && (dd<='z') ) // if value of dd is between the ascii values of aa and zz, do block { return 1; } else { return 0; } } int digit(char dd) { if( (dd<='0') && (dd<='9') ) // if value of dd is btween ascii values of 0 and 9, do block { return 1; } else { return 0; } }