Skip to content

Instantly share code, notes, and snippets.

@digi0ps
Created July 28, 2017 09:26
Show Gist options
  • Save digi0ps/1b8de83b0e9f3adf6dee355049d8d72d to your computer and use it in GitHub Desktop.
Save digi0ps/1b8de83b0e9f3adf6dee355049d8d72d to your computer and use it in GitHub Desktop.
#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