Whenever I run this program(on Linux):
Code:
#include <stdio.h>
#include <stdlib.h>
int *letter_count(char *s);
int main(int argc,char **argv)
{
int *lc=calloc(26,sizeof(char));
lc=letter_count(argv[1]);
for(int i=0;i<26;i++)
{
printf("%c: %d\n",(char)(i+'a'),lc[i]);
}
return 0;
}
int *letter_count(char *s)
{
int *lc=calloc(26,sizeof(char));
for(int i=0;s[i];i++)
{
lc[(int)(s[i]-'a')]++;
}
return lc;
}
I keep getting 135073 for 'k' when no k's has been entered. I tracked it back to the calloc which seems to be where k gets its strange value. Why would calloc produce this number?