Sunday, 15 September 2013

Hi friends, In this program how this line work "flag[str[i]-'a']++;" can anyone explain?

Hi friends, In this program how this line work "flag[str[i]-'a']++;" can
anyone explain?

I have doubt in this line "flag[str[i]-'a']++;" how this line work. For
full program visit
"http://www.programmingsimplified.com/c/source-code/c-anagram-program"
char str[44];
int flag[26],i=0;
gets(str);
while(str[i]!='\0')
{
flag[str[i]-'a']++; // How this line work
i++;
}
i=0;
while(str[i]!='\0')
{
printf("\n%d, %d ",str[i]-'a');
i++;
}

No comments:

Post a Comment