Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Sentence Analyzer In this problem you will design and implement, a basic charact

ID: 3938827 • Letter: S

Question

Sentence Analyzer In this problem you will design and implement, a basic character frequency program. Specifically, you will write a program that opens a specified text file, and count frequency of letters. Ignore all punctuation marks. All of your code should be placed in one file, text Analyzer. c. The program accepts the file name as a command line argument so that it is executable as follows: ./textAnalyzer infile.txt. To be more specific, your program will open the text file and read each line and calculate the total frequencies of each character excluding punctuation marks. Make sure the program is case insensitive, meaning the program should count A and a as the same characters. Your output might look something like this:

Explanation / Answer

// C program textAnalyzer.c

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <string.h>

int main(int argc, char const *argv[])
{
   if(argc < 2)
   {
       printf("Input file missing ");
       return 0;
   }


FILE *inputFile;
   int i;
   char ch;
   int characterCount[26] = {0};

   // open file
   inputFile = fopen(argv[1],"r");  

   while(!feof(inputFile))
   {
       ch = fgetc(inputFile);
       ch = tolower(ch);
       characterCount[ch - 'a']++;  
   }

   printf("Character frequency in infile.txt ");
   printf("Character Count ");

   for(i = 0;i < 26;i++)
       printf("%c %d ",97+i,characterCount[i]);
  
   fclose(inputFile);

return 0;
}


/*
infile.txt
my name is ayush verma.
I am from bhopal madhya pradesh
I studied at IIT kharagpur.
pqrstwzyz

output:
Character frequency in infile.txt
Character   Count
a   11
b   1
c   0
d   4
e   4
f   1
g   1
h   5
i   6
j   0
k   1
l   1
m   6
n   1
o   2
p   4
q   1
r   6
s   5
t   4
u   3
v   1
w   1
x   0
y   4
z   2


*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote