what is The Peroblem In This Code ?
Code:
# include <iostream>
using namespace std;
# include <cctype>
# include <cstring>
void readLine (char*);
void printLine (char*);
void display_Count_of_Words_Lenght (char*);
void dispaly_Number_of_Words_In_Sentence (char*);
void display_Uppercase_Frequency (char*);
void dispaly_SubString_Frequency (char*);
void replace_string_with_stars (char*);
void main ( )
{
void (* AnalyseText[7])(char *)={readLine, printLine, display_Count_of_Words_Lenght,
dispaly_Number_of_Words_In_Sentence , display_Uppercase_Frequency,
replace_string_with_stars };
int choice;
cout<<"Enter a choice :";
cin>>choice;
while (choice >=0 && choice <7){
(* AnalyseText[choice])(choice);}
}
void readLine (char* string1){
cout<<"Enter a line of text:\n";
cin.getline( string1, 100 );
}
void printLine (char* string1){
cout<<"The line of text is:"<<string1<<endl;
}
void display_Count_of_Words_Lenght (char* string1){
int lenght;
int count[ ]={0};
for (int i=0; i<10; i++)
cout[i]=0;
char *token= strtok (string1, " ");
while (token != '\0'){
lenght= strlen (token);
if(lenght<=10)
count[lenght-1]++;
token= strtok ('\0', " ");
}
for(int j=0; j<10; j++)
cout<<"lenght"<<j<<":"<<count[j]<<"occurences";
}
void dispaly_Number_of_Words_In_Sentence (char* string1){
int count=0;
char* token= strtok (string1, " ");
while (token != '\0'){
count++;
token= strtok ('\0', " ");
}
for (int i=0; *(string1 +i) !='\0'; i++)
cout<<"sentence"<<i<<":"<<count<<"words";
}
void display_Uppercase_Frequency (char* string1){
int count=0;
for(int i=0; *(string1+i) != '\0'; i++){
if( isupper (*(string1+i)) )
count++;}
cout<<"isupper: "<<count;
}
void dispaly_SubString_Frequency (char* string1){
int count=0;
char* string2;
cout<<"Enter a string :\n";
cin.getline (string2, 100);
char * ptr= strstr (string1, string2);
while (ptr != '\0'){
count++;
ptr= strstr (ptr+1, string2);}
cout<<"The string"<<ptr<<"is repeated"<<count<<"times";
}
void replace_string_with_stars (char* string1){
char *string2;
cout<<"Enter a string :\n";
cin.getline (string2, 100);
char *ptr = strstr (string1, string2);
while ( ptr != '\0' ){
strcpy (string1, "*****");
ptr= strstr (ptr+1, string2);
}
}