write a program that will open the file, count the number of occurences of each word in the the complete works of shakespeare.
You will then tabulate this information in another file.
Answer / Awashesh Kumar Tiwari
Here's an example C program to count the occurrence of each word in Shakespeare's works and save the results in a file:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX_WORDS 10000
#define BUFFER_SIZE 256
struct WordCount {
char word[BUFFER_SIZE];
int count;
};
void readFile(const char *filename, struct WordCount words[], int maxWords) {
FILE *file = fopen(filename, "r");
if (file == NULL) return;
char line[BUFFER_SIZE];
char word[BUFFER_SIZE];
int index = 0;
while (fgets(line, BUFFER_SIZE, file)) {
char *token = strtok(line, " ,.n");
while (token != NULL) {
// Remove punctuation and convert to lowercase
int len = strlen(token);
for (int i = 0; i < len; ++i) {
if (!isalpha((unsigned char)token[i])) token[i] = '