Question: In Linux 1) Use strtok to extract words from a sentence and store them in an array. Display the number of words as below. algorithm:

In Linux

1)

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? tell me the reanson

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!