### C program to find frequency of each character in a string

//C/Cpp/C++ program to find frequency of each characters in a string
//C/Cpp/C++ program to find non repeating characters in a string
//C/Cpp/C++ program to find repeating characters in a string
//C/Cpp/C++ program to output a1b2c3d4 when input is "abbcccdddd"
/*Idea is to keep count of each characters
'a'=count occurs how many times 0,1,2.3..
'b'=count occurs how many times 0,1,2,3..
.
.
'z'=count occurs how many times 0,1,2,3....
*/
#include<iostream>
using namespace std;
#include<stdio.h>
#include<string.h>
int main()
{
char a='a';
cout<<"a-97="<<a-97<<endl;//0
cout<<"'a'-97="<<'a'-97<<endl;//0

cout<<"manin()\n";
char arr[]="abbccc";
int count;
int i;
for(i=0;i<26;i++)
count[i]=0;

i=0;
//while(arr[i]!='\0')
for(i=0;i<strlen(arr);i++)
{
printf("arr[i]=%c arr[i]-97=%d count[arr[i]-97]]=%d\n",arr[i],arr[i]-97,count[arr[i]-97]);
if(arr[i]>='a' && arr[i]<='z')
count[arr[i]-97]=count[arr[i]-97]+1;//count[arr[i]-97]++;
if(arr[i]>='A' && arr[i]<='Z')
count[arr[i]-65]=count[arr[i]-65]+1;//count[arr[i]-65]++;
//i++;
}

printf("\nPrinting frequency of each character:\n");
for(i=0;i<25;i++)
{
if(count[i]>0)//characters which occurs atleast once
printf(" %c%d",i+97,count[i]);//a1b2c3
}
printf("\nPrinting repeated character:\n");
for(i=0;i<25;i++)
{
if(count[i]>1)//characters which occurs atleast 2
printf(" %c%d",i+97,count[i]);//a1b2c3
}
printf("\nPrinting character which are unique or none repeating characters:\n");
for(i=0;i<25;i++)
{
if(count[i]==1)//characters which occurs only once or uniquely
printf(" %c%d",i+97,count[i]);//a1b2c3
}

printf("\n");
return 0;
}
/*
a-97=0
'a'-97=0
manin()
arr[i]=a arr[i]-97=0 count[arr[i]-97]]=0
arr[i]=b arr[i]-97=1 count[arr[i]-97]]=0
arr[i]=b arr[i]-97=1 count[arr[i]-97]]=1
arr[i]=c arr[i]-97=2 count[arr[i]-97]]=0
arr[i]=c arr[i]-97=2 count[arr[i]-97]]=1
arr[i]=c arr[i]-97=2 count[arr[i]-97]]=2

Printing frequency of each character:
a1 b2 c3
Printing repeated character:
b2 c3
Printing character which are unique or none repeating characters:
a1
http://www.codeforwin.in/2015/04/c-program-to-calculate-the-frequency-of-each-character-in-a-line.html
*/