Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

From Zero To Data Hero With Chatgpt

Authors: Andrew Wu

1st Edition

B0CQRJPXD9, 979-8989523009

More Books

Students also viewed these Databases questions

Question

7. Identify four antecedents that influence intercultural contact.

Answered: 1 week ago

Question

5. Describe the relationship between history and identity.

Answered: 1 week ago