#include<stdio.h>
//#include<conio.h>
#include<ctype.h>
#define TRUE 1
#define FALSE 0
#define BOOLEAN int
typedef struct WordStructure {
char word[ 50 ] ;
int frequency;
int length;
} Word;
BOOLEAN isEqualsIgnoreCase( char original[ ] , char toBeCompared[ ] ) ;
int calcNumOfCharacters( char original[ ] ) ;
int fetchWords( char original[ ] , Word w[ ] ) ;
int isExists( Word w[ ] , Word temp, int length) ;
void getInputText( char original[ ] ) ;
int countWords( Word w[ ] , int length) ;
int countPunctuations( char original[ ] ) ;
int countPrepositions( Word w[ ] , Word preposition[ ] , int wordLength, int prepoLength) ;
double arithmeticMean( Word words[ ] , int length) ;
int noOfWordsWithOddLengths( Word words[ ] , int length) ;
int noOfWordsWithEvenLengths( Word words[ ] , int length) ;
void printALlTheWords( Word words[ ] , int length) ;
void main( ) {
char original[ 1000 ] ;
char prepositions[ 1000 ] ;
Word words[ 400 ] ;
Word prepo[ 400 ] ;
int wordLength = 0 , prepoLength = 0 ;
printf ( "\n Enter original input text: \n " ) ; getInputText( original) ;
printf ( "\n Enter prepositions: \n " ) ; getInputText( prepositions) ;
wordLength = fetchWords( original, words) ;
prepoLength = fetchWords( prepositions, prepo) ;
printALlTheWords( words, wordLength) ;
printALlTheWords( prepo, prepoLength) ;
printf ( "\n Number of characters are: \n %d\n " , calcNumOfCharacters
( original
) ) ; printf ( "\n Number of words are: \n %d\n " , countWords
( words
, wordLength
) ) ; printf ( "\n Arithmetic Mean: \n %.2f\n " , arithmeticMean
( words
, wordLength
) ) ; printf ( "\n Number of punctuation are: \n %d\n " , countPunctuations
( original
) ) ; printf ( "\n Number of prepositions are: \n %d\n " , countPrepositions
( words
, prepo
, wordLength
, prepoLength
) ) ; printf ( "\n Number of words with even length are: \n %d\n " , noOfWordsWithEvenLengths
( words
, wordLength
) ) ; printf ( "\n Number of words with odd length are: \n %d\n " , noOfWordsWithOddLengths
( words
, wordLength
) ) ; }
void printALlTheWords( Word w[ ] , int length) {
int i = 0 ;
for ( i = 0 ; i < length; i++ ) {
printf ( "%20s\t %2d\t %2d\n " , w
[ i
] .
word , w
[ i
] .
length , w
[ i
] .
frequency ) ; }
}
void getInputText( char original[ ] ) {
int i = 0 ;
char ch;
original[ i] = ch;
i++;
}
original[ i] = '\0 ' ;
}
BOOLEAN isEqualsIgnoreCase( char original[ ] , char toBeCompared[ ] )
{
return TRUE;
}
int calcNumOfCharacters( char original[ ] )
{
int i= 0 ;
while ( original[ i] != '\0 ' )
i++;
return i;
}
int fetchWords( char original[ ] , Word w[ ] )
{
int end= 0 , pos, temp= 0 , i= 0 , j, l;
Word theWord;
pos = 0 ;
while ( ! end)
{
while ( ( ! isalnum ( original
[ pos
] ) ) && ( original
[ pos
] != '\0 ' ) ) pos++;
if ( original[ pos] != '\0 ' ) {
if ( i== 0 )
{
j= 0 ;
while ( ( isalnum ( original
[ pos
] ) ) && ( original
[ pos
] != '\0 ' ) ) {
w[ i] .word [ j] = original[ pos] ;
j++;
pos++;
}
w[ i] .length = j;
w[ i] .frequency = 1 ;
i++;
}
else
{
j= 0 ;
while ( ( isalnum ( original
[ pos
] ) ) && ( original
[ pos
] != '\0 ' ) ) {
theWord.word [ j] = original[ pos] ;
j++;
pos++;
}
theWord.length = j;
theWord.frequency = 1 ;
temp= isExists( w, theWord, i) ;
if ( temp==- 1 )
{
for ( l= 0 ; l< theWord.length ; l++ )
w[ i] .word [ l] = theWord.word [ l] ;
w[ i] .length = l;
w[ i] .frequency = 1 ;
i++;
}
else
w[ temp] .frequency = w[ temp] .frequency + 1 ;
}
}
if ( original[ pos] == '\0 ' )
end= 1 ;
}
return i;
}
int isExists( Word SourceArray[ ] , Word toBeFound, int SourceArrayLength)
{
int i, j=- 1 , k, kontinue= 0 ;
for ( i= 0 ; i< SourceArrayLength; i++ )
{
if ( SourceArray[ i] .length == toBeFound.length )
{
k= 0 , kontinue= 1 ;
while ( k < SourceArray[ i] .length && kontinue)
{
if ( SourceArray
[ i
] .
word [ k
] == toBeFound.
word [ k
] || toupper ( SourceArray
[ i
] .
word [ k
] ) == toupper ( toBeFound.
word [ k
] ) ) {
k++;
}
else
{
kontinue = 0 ;
}
}
}
if ( kontinue)
{
j= i;
break ;
}
}
return j;
}
int countWords( Word w[ ] , int length)
{
int sum= 0 , i;
for ( i= 0 ; i< length; i++ )
sum= sum+ w[ i] .frequency ;
return sum;
}
int countPunctuations( char original[ ] )
{
int i= 0 , count= 0 ;
while ( original[ i] != '\0 ' )
{
if ( original[ i] == '.' || original[ i] == '?' || original[ i] == '!' || original[ i] == ':' || original[ i] == ';' || original[ i] == '-' || original[ i] == '_' || original[ i] == ',' || original[ i] == '\' ' || original[ i] == '"' || original[ i] == '/' )
count++;
i++;
}
return count;
}
int countPrepositions( Word w[ ] , Word preposition[ ] , int wordLength, int prepoLength)
{
int i, count= 0 , temp=- 1 ;
for ( i= 0 ; i< prepoLength; i++ )
{
temp= isExists( w, preposition[ i] , wordLength) ;
if ( temp!=- 1 )
count= count+ w[ temp] .frequency ;
}
return count;
}
double arithmeticMean( Word words[ ] , int length)
{
int i;
double x, n= 0.0 , sum= 0.0 ;
for ( i= 0 ; i< length; i++ )
{
sum= sum+ ( words[ i] .length * words[ i] .frequency ) ;
n= n+ words[ i] .frequency ;
}
x= sum/ n;
return x;
}
int noOfWordsWithOddLengths( Word words[ ] , int length)
{
int i, count= 0 ;
for ( i= 0 ; i< length; i++ )
{
if ( words[ i] .length % 2 != 0 )
count= count+ words[ i] .frequency ;
}
return count;
}
int noOfWordsWithEvenLengths( Word words[ ] , int length)
{
int i, count= 0 ;
for ( i= 0 ; i< length; i++ )
{
if ( words[ i] .length % 2 == 0 )
count= count+ words[ i] .frequency ;
}
return count;
}
I2luY2x1ZGU8c3RkaW8uaD4KLy8jaW5jbHVkZTxjb25pby5oPgojaW5jbHVkZTxjdHlwZS5oPgojZGVmaW5lIFRSVUUgMQojZGVmaW5lIEZBTFNFIDAKI2RlZmluZSBCT09MRUFOIGludAogCnR5cGVkZWYgc3RydWN0IFdvcmRTdHJ1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dGVtcF0uZnJlcXVlbmN5KzE7Cn0KfQppZihvcmlnaW5hbFtwb3NdPT0nXDAnKQplbmQ9MTsKIAp9CnJldHVybiBpOwp9ICAgICAgICAgICAgICAgICAgCmludCBpc0V4aXN0cyhXb3JkIFNvdXJjZUFycmF5W10sIFdvcmQgdG9CZUZvdW5kLCBpbnQgU291cmNlQXJyYXlMZW5ndGgpCnsKaW50IGksaj0tMSxrLGtvbnRpbnVlPTA7CmZvcihpPTA7aTxTb3VyY2VBcnJheUxlbmd0aDtpKyspCnsKIAppZihTb3VyY2VBcnJheVtpXS5sZW5ndGg9PXRvQmVGb3VuZC5sZW5ndGgpCnsKICAgICBrPTAsa29udGludWU9MTsKICAgICAgICAgICAgICAgIHdoaWxlIChrIDwgU291cmNlQXJyYXlbaV0ubGVuZ3RoJiZrb250aW51ZSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBpZiAoU291cmNlQXJyYXlbaV0ud29yZFtrXT09dG9CZUZvdW5kLndvcmRba118fHRvdXBwZXIoU291cmNlQXJyYXlbaV0ud29yZFtrXSkgPT0gdG91cHBlcih0b0JlRm91bmQud29yZFtrXSkpCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBrKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAga29udGludWUgPSAwOwogICAgICAgICAgICAgICAgICAgIH0gICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIH0gICAgICAgIAogCn0KaWYoa29udGludWUpCnsKaj1pOwpicmVhazsKfQp9CnJldHVybiBqOwp9CmludCBjb3VudFdvcmRzKFdvcmQgd1tdLCBpbnQgbGVuZ3RoKQp7CmludCBzdW09MCxpOwpmb3IoaT0wO2k8bGVuZ3RoO2krKykKc3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