#include <stdio.h>
#include <string.h>
int main()
{
char string[100];
int c = 0, count[26] = {0};
printf("Enter a string\n");
gets(string);
while (string[c] != '\0')
{
if (string[c] >= 'a' && string[c] <= 'z')
count[string[c]-'a']++; /*I do not understand this line/*
c++;
}
for (c = 0; c < 26; c++)
{
if (count[c] != 0)
printf("%c %d \n",c+'a',count[c]);
}
return 0;
}
Mir Mahfuz
0
Newbie Poster
Recommended Answers
Jump to PostHi Mir Mahfuz welcome to Daniweb! :)
What the line does is mapping every character of your string to an index in the your count array.
Say string[c] = 'b' so ('b' - 'a') will be 1 and count[1] will be incremented.
Say string[c] = 'a' so ('a' - 'a') …
All 2 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.