I am doing code for CAESAR CIPHER. I need to built a histogram or frequency distribution for the output. I thought that finding out the frequency of the ASCII code, then print the frequency with * by using loop. But my code din't have array, can't do ++freq[c[i]].
I have no idea. Anyone can help?
#include <stdio.h>
#include <iostream.h>
void encrypt(int shift);
int main()
{
int shift;
int decOrEnc;
printf("Enter shift amount (1-25): ");
scanf("%d", &shift);
if (shift < 0)
{
printf("Bad Input.");
return 0;
}
printf("Type 1 to Encrypt or 0 to Decrypt: ");
scanf("%d", &decOrEnc);
if (decOrEnc != 0 && decOrEnc !=1)
{
printf("Bad Input.");
return 0;
}
while(getchar() != '\n');
if (decOrEnc == 1)
encrypt(shift);
else
{
shift = -1 * shift;
encrypt(shift);
}
getchar();
}
void encrypt(int shift)
{
char ch;
printf("Please Enter Your ID : ");
ch = getchar();
while(ch != '\n')
{
if (ch == ' ')
putchar(ch);
else
{
if(shift == 1)
putchar(ch + shift);
else
putchar(ch - shift);
}
ch = getchar();
}
{
unsigned int c;
while (1)
{
printf("\n" );
c = getchar();
printf("%c - %d", c, c );
}
}
/* int freq[100]={0};
for(int i=0; i<127; i++)
{
++freq[c[i]];
}*/
system("pause");
putchar(ch);
}