NOTE This program reads the strings entered from standard in

NOTE****: This program reads the strings entered from standard input... Not from an actual FILE.

Solution

#include <stdio.h>
#include <ctype.h>

int lower[26] = {0};
int upper[26] = {0};
int digit[10] = {0};
int special[32] = {0};

char special_char[32] = {\'!\', \'\"\', \'#\', \'$\', \'%\', \'&\', \'\\\'\', \'(\', \')\', \'*\', \'+\', \',\', \'-\', \'.\', \'/\', \':\', \';\', \'<\', \'=\', \'>\', \'?\', \'@\', \'[\',\'\\\\\', \']\', \'^\', \'_\', \'`\', \'{\',\'|\', \'}\', \'~\'};

int get_max()
{
int i = 0;
int max = lower[0];
for(i = 1; i < 26; i++)
{
if (max < lower[i])
{
max = lower[i];
}
}

for(i = 0; i < 26; i++)
{
if (max < upper[i])
{
max = upper[i];
}
}

for(i = 0; i < 10; i++)
{
if (max < digit[i])
{
max = digit[i];
}
}

for(i = 0; i < 32; i++)
{
if (max < special[i])
{
max = special[i];
}
}
return max;
}

void printCharWithCount(int count)
{
if (count >= 0)
printf(\"Character occurring\\t%d times : \", count);
else
printf(\"Character not found in the input : \");

int i = 0;
for(i = 0; i < 26; i++)
{
if (lower[i] == count)
{
lower[i] = -1;
printf(\"%c \", \'a\' + i);
}
}

for(i = 0; i < 26; i++)
{
if (upper[i] == count)
{
upper[i] = -1;
printf(\"%c \", \'A\' + i);
}
}

for(i = 0; i < 10; i++)
{
if (digit[i] == count)
{
digit[i] = -1;
printf(\"%c \", \'0\' + i);
}
}

for(i = 0; i < 32; i++)
{
if (special[i] == count)
{
special[i] = -1;
printf(\"%c \", special_char[i]);
}
}
printf(\"\ \");
}

void print()
{
int max = get_max();

while(max >= 0)
{
printCharWithCount(max);
max = get_max();
}

}

void checkAndSetSpecialChar(char c)
{
int i = 0;
for(i = 0; i < 32; i++)
{
if (special_char[i] == c)
{
special[i]++;
break;
}
}
}

void main()
{
int i = 0;

for(i = 0; i < 26; i++)
{
lower[i] = 0;
upper[i] = 0;
}
for(i = 0; i < 10; i++)
digit[i] = 0;
for(i = 0; i < 32; i++)
special[i] = 0;

int c;
while((c = getchar() )!= EOF)
{
if (islower(c))
{
lower[c-\'a\']++;
}
if (isupper(c))
{
upper[c-\'A\']++;
}
if (isdigit(c))
{
digit[c-\'0\']++;
}
checkAndSetSpecialChar(c);
}

int lower_char_count = 0;
int upper_char_count = 0;
int digit_count = 0;
int special_count = 0;
for(i = 0; i < 26; i++)
{
lower_char_count += lower[i];
upper_char_count += upper[i];
}

for(i = 0; i < 10; i++)
{
digit_count += digit[i];
}

for(i = 0; i < 32; i++)
{
special_count += special[i];
}
int total = lower_char_count + upper_char_count + digit_count + special_count;
printf(\"%d characters\ \", total);

printf(\"lowercase=%d and uppercase=%d and digit=%d and special=%d\ \ \", lower_char_count, upper_char_count, digit_count, special_count);
print();
}

NOTE****: This program reads the strings entered from standard input... Not from an actual FILE.Solution#include <stdio.h> #include <ctype.h> int lo
NOTE****: This program reads the strings entered from standard input... Not from an actual FILE.Solution#include <stdio.h> #include <ctype.h> int lo
NOTE****: This program reads the strings entered from standard input... Not from an actual FILE.Solution#include <stdio.h> #include <ctype.h> int lo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site