home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************/
- /* This program will read in a text file and compute the number */
- /* of alpha, numeric, blank, or other characters found. */
- /*******************************************************************/
-
- /* Compile and link this program, then rename it to SCANFILE.TOS */
-
- #include "stdio.h"
-
- main()
- {
- FILE *input_file;
- char input_name[15];
- int count = 0,charin;
- int digit = 0,other = 0;
- int alpha = 0,space = 0;
-
-
- printf("File Scanning Program\n");
- printf("\nThis program will count occurrences of digits,\n");
- printf("alphabetic characters, blanks in a text file\n");
- printf("\n");
- printf("Enter the name of the input file : ");
- scanf("%s",input_name);
- input_file = fopen(input_name, "r");
- if (input_file == NULL) {
- printf("Cannot open input file.\n");
- exit(0);
- }
- for(count=0;;++count) {
- charin = getc(input_file);
- if ((charin >= 'A') && (charin <= 'z')) alpha++;
- else if ((charin >= '0') && (charin <='9')) digit++;
- else if (charin == ' ') space++;
- else if (charin == EOF) break;
- else other++;
- }
- printf("\nSUMMARY\n");
- printf("There were %d digits entered\n",digit);
- printf("Along with %d alphabetic characters,\n",alpha);
- printf("%d whitespace characters,\n",space);
- printf("and %d other characters.\n",other);
- gemdos(0x1);
- }
-
-