Question
In Linux 1) 10) Use strtok to extract words from a sentence and store them in an array. Display the number of words as below.
In Linux
1)
10) Use strtok to extract words from a sentence and store them in an array. Display the number of words as below.
algorithm:
read a line
tokenize
display tokens
Enter a sentence
aa bcd e e ff aa bcd bcd hijk lmn al bcd
You entered aa bcd e e ff aa bcd bcd hijk lmn al bcd
There were 12 words:
aa
bcd
e
e
ff
aa
bcd
bcd
hijk
lmn
al
bcd
The original sentence was: aa bcd e e ff aa bcd bcd hijk lmn al bcd
2) What is wrong with the following program? How can you fix it?
void getstr(char *str){
printf(enter a string );
scanf(%s, str);
}
int main(){
char * strarr[10]={NULL};
getstr(strarr[0]);
printf(we got %s , strarr[0]);
3) Write a program that reads a long sentence and displays the frequency of each word as below. It also prints the word that has the maximum frequency. Use as many functions as possible to split your program into small pieces.
algorithm:
read a line
tokenize
display tokens
compute frequency
for each token
if it is already in freq[] array, increase its frequency
otherwise store in freq[] and initialize its frequency=1
display frequencies
compute max frequency word and display it
Enter a sentence
aa bcd e e ff aa bcd bcd hijk lmn al bcd
You entered aa bcd e e ff aa bcd bcd hijk lmn al bcd
There were 12 words: aa bcd e e ff aa bcd bcd hijk lmn al bcd
Frequncies: aa 2 bcd 4 e 2 ff 1 hijk 1 lmm 1 al 1
The word with the max freq: bcd
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started