Category : C Source Code
Archive   : C-TUTOR.ZIP
Filename : CHARCLAS.C

 
Output of file : CHARCLAS.C contained in archive : C-TUTOR.ZIP
/* Chapter 13 - Program 2 */
#include "stdio.h"
#include "ctype.h" /* Note - your compiler may not need this */

main()
{
FILE *fp;
char line[80], filename[24];
char *c;

printf("Enter filename -> ");
scanf("%s",filename);
fp = fopen(filename,"r");

do {
c = fgets(line,80,fp); /* get a line of text */
if (c != NULL) {
count_the_data(line);
}
} while (c != NULL);

fclose(fp);
}

count_the_data(line)
char line[];
{
int whites, chars, digits;
int index;

whites = chars = digits = 0;

for (index = 0;line[index] != 0;index++) {
if (isalpha(line[index])) /* 1 if line[] is alphabetic */
chars++;
if (isdigit(line[index])) /* 1 if line[] is a digit */
digits++;
if (isspace(line[index])) /* 1 if line[] is blank, tab, */
whites++; /* or newline */
} /* end of counting loop */

printf("%3d%3d%3d %s",whites,chars,digits,line);
}


  3 Responses to “Category : C Source Code
Archive   : C-TUTOR.ZIP
Filename : CHARCLAS.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/