We are going to supply you with a file which contains a very large number of wor
ID: 3632547 • Letter: W
Question
We are going to supply you with a file which contains a very largenumber of words. No definitions, just lots of words. It's the kind of
data that you could use to write a spell checker or to gain an unfair
advantage while playing scrabble-like games online with friends (or
enemies).
Your first program ((assume this program is called 'first') will read
in characters or lines of text and count the number of lines, the
number of alphabetic characters (breaking them down into upper case
and lower case), the number of punctuation characters and the number
of numeric characters. Upon termination of input it will report all
of the statistics.
Note: You will recall that fgets and getchar can detect end of file
(EOF). In order to generate an end of file from the keyboard you must
be at the beginning of a line and you can type CTRL/Z on
Windows or CTRL/D on Linux.
Explanation / Answer
please rate - thanks
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
int menu();
int countupper(char[]);
int countlower(char[]);
int countpunct(char[]);
int countnumbers(char[]);
int main()
{char s[300];
char *instring;
char filename[30];
FILE *input;
int numbers=0,upper=0,lower=0,lines=0,punct=0;
int choice;
printf("enter input file name: ");
scanf("%s",&filename);
input = fopen(filename,"r");
if(input == NULL)
{ printf("Error opening input file! ");
return 0;
}
instring=fgets(s,300,input);
while(instring!=NULL)
{lines++;
upper+=countupper(s);
lower+=countlower(s);
punct+=countpunct(s);
numbers+=countnumbers(s);
instring=fgets(s,300,input);
}
fclose(input);
printf("The number of lines is: %d ",lines);
printf("The number of upper case letters is: %d ",upper);
printf("The number of lower case letters is: %d ",lower);
printf("The number of punctuations is: %d ",punct);
printf("The number of numbers is: %d ",numbers);
getch();
return 0;
}
int countupper(char s[])
{int n,count=0;
for(n=0;s[n]!='';n++)
if(isupper(s[n]))
count++;
return count;
}
int countlower(char s[])
{int n,count=0;
for(n=0;s[n]!='';n++)
if(islower(s[n]))
count++;
return count;
}
int countnumbers(char s[])
{int n,count=0;
for(n=0;s[n]!='';n++)
if(isdigit(s[n]))
count++;
return count;
}
int countpunct(char s[])
{int n,count=0;
for(n=0;s[n]!='';n++)
if(ispunct(s[n]))
count++;
return count;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.