Professional Documents
Culture Documents
EEE105 Post Lab Experiment-7
EEE105 Post Lab Experiment-7
Exp. No.: 07
Group no.: 06
2023-2-80-008
Date of
performance: Instructor’s
Comment and
Signature:
06-05-2024
Date of
Submission:
16-05-2024
Answer to the Question No: 01
int words = 0;
for (int i = 0; line[i] != '\0'; i++) {
if (line[i] == ' ' && line[i - 1] != ' ') {
words++;
}
}
if (line[0] != ' ') {
words++;
}
printf("Number of words: %d\n", words);
Comment:
Initially, a sentence is inputted into this program and is stored in the array line. The
sentence's word count is then calculated and displayed. The characters that are
indexed as EVEN and ODD are then stored in other arrays labeled EVEN and
ODD, respectively, and the cases are switched as instructed. The contents of the
ODD and EVEN arrays are finally shown independently.
Answer to the Question No: 02
The following C code is:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
typedef struct {
char word[MAX_WORD_LEN];
int count;
} WordFrequency;
toLowercase(str);
token = strtok(str, " ,.-?!");
while (token != NULL) {
int index = findWord(words, wordCount, token);
if (index == -1) {
strcpy(words[wordCount].word, token);
words[wordCount].count = 1;
wordCount++;
} else {
words[index].count++;
}
token = strtok(NULL, " ,.-?!");
}
int maxCount = 0;
int maxIndex = 0;
for (int i = 0; i < wordCount; i++) {
if (words[i].count > maxCount) {
maxCount = words[i].count;
maxIndex = i;
}
}
printf("Most used sequence/word in the string is: '%s' and it occurred: %d times.\n",
words[maxIndex].word, maxCount);
return 0;
}
Output:
Comment:
This code is a C program that determines the frequency of each word by tokenizing
a user-supplied string into words. It tokenizes the string using a straightforward
method based on spaces and frequently used punctuation (exclamation points,
question marks, dashes, and commas).