Created
July 28, 2017 09:26
-
-
Save digi0ps/1b8de83b0e9f3adf6dee355049d8d72d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
void calc_freq(char* str){ | |
int freq[255], i, j, temp; | |
for(i=0;i<255;i++) | |
freq[i] = 0; | |
for(i=0;str[i]!='\0';str++){ | |
int ascii = (int)str[i]; | |
freq[ascii]++; | |
} | |
printf("\nFrequency of the characters:\n"); | |
for(i=0;i<255;i++){ | |
if (freq[i]){ | |
char c = (char)i; | |
if(c==' ')continue; | |
printf("%c - %d\n", c, freq[i]); | |
} | |
} | |
} | |
int main() { | |
char stry[100]; | |
int i; | |
puts("Enter a string: "); | |
gets(stry); | |
printf("Original String: "); | |
puts(stry); | |
calc_freq(stry); | |
getchar(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment