Question: In Linux using by c++ Language 1) Try below and explain why it behaves strange. How can you fix it? int x1; char x2[12]; x1=33;

In Linux using by c++ Language

1) Try below and explain why it behaves strange. How can you fix it?

int x1;

char x2[12];

x1=33;

strcpy(x2,"abcdefghijkl");

printf("%d %s",x1,x2);

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

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!