What does the following program do? #include <stdio.h> #include <stdlib.h> #incl
ID: 3669444 • Letter: W
Question
What does the following program do?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
FILE *fpt;
int count[20],i,s;
char word[80];
if (argc != 2)
{
printf("Usage: wordcount [filename] ");
exit(0);
}
if ((fpt=fopen(argv[1],"r")) == NULL)
{
printf("Unable to open %s for reading ",argv[1]);
exit(0);
}
for (i=0; i<21; i++)
count[i]=0;
while (fscanf(fpt,"%s",word) == 1)
{
s=strlen(word);
if (s >= 2 && s <= 20)
count[s]++;
}
for (i=2; i<=20; i++)
if (count[i] > 0)
printf("Words of length %d: %d ",i,count[i]);
}
Select one:
a. Prints Words of length
b. Prints total count of words of each length
c. Prints length of each word
d. Prints total count of words
Explanation / Answer
b. Prints total count of words of each length
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.