Write a function that returns how many different not includi

Write a function that returns how many different (not including repeated entries) characters are in the string. \'T\' is the same as \'t\' once you have either \'T\' or \'t\' it should appear only once. Using this function display a table to indicate the number of different characters, and the number of times each character appears in the string, for example Output: Character Number Of Times P 1 R 2 O 1 G 3 A 2 M 3 I 2 N 3 1 S 2 E 1 T 1 Total: 12

Solution

C code :

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

void count_character(char str[]){
char ch,*count_str;
int *count_num;
int i=0,j=0,k=0;

  
for(i=0;i<strlen(str);i++){
ch = toupper(str[i]);
for(k=0; k<strlen(count_str); k++){
if(ch == count_str[k]){
count_num[k] = count_num[k]+1;
goto skip;
}
}


count_str[j] = ch;
count_num[j++] = 1;
skip : { };
}
printf(\"Character\\tNumber of Times\ \");
for(i=0;i<strlen(count_str);i++){
printf(\"%c \\t\\t %d\ \",count_str[i],count_num[i]);
}
printf(\"Total : %d \ \",strlen(count_str));
}

int main()
{
char str[] = \"Programming Assignment\";
count_character(str);
return 0;
}

NOTE :

i took a count_character(str) function which is used to calculate the character count. In that function i created 2 array pointers, one is char array and other is integer array pointer. count_str is used to store a character and count_num is used to maintain character count. every time one character is taken from string and converted into UPPER CASE , then i checked wheather character is repeated or not. if repeated count will be incremented else it add the character to count_str and count_num arrays. if Program LABEL and GOTO is used , when any character is found in count_str array then it skips the adding that character to count_str array.

 Write a function that returns how many different (not including repeated entries) characters are in the string. \'T\' is the same as \'t\' once you have either

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site