Task: Write a program that will read a line of text and output the number of occurrences each letter.
#include <iostream>
#include <string>
#include <cstring>
#define N 100
using namespace std;
int main()
{
char alphabet[27] = "abcdefghijklmnopqrstuvwxyz";
int alphacount[26];
char lot[N], *p1;
int txtlen, *p2;
cout << " Enter a line of text: " << endl;
cin.getline(lot, 99);
txtlen = strlen(lot);
p1 = lot;
p2 = &txtlen;
for (int x = 0; x < *p2; x++)
{
for (int y = 0; y < 26; y++)
{
if (*p1 == alphabet[y])
{
alphacount[y]++;
p1++;
}
}
}
cout <<;
}
What is the condition needed, and what variable will be used to output the occurrences of letter? For example:
> enter a line of text : mervlala
Output:
a - 2,
e - 1,
l - 2,
m - 1,
r - 1,
v - 1