In C Language: Letters Selection Process (assigned to Programmer A): If the user
ID: 3689662 • Letter: I
Question
In C Language:
Letters Selection Process (assigned to Programmer A):
If the user selects to “play with letters” (option 2), the program will then execute the following subsequent selection
criteria:
--== Playing with Letters ==--
What would you like to do?
1. Find more than one occurrence of a character
2. Find character occurrence that has a vowel before it
Enter 1 or 2. (0 to return to main selection):
The selection value entered by the user must be a numeric value of one, two, or zero. If any other value is entered,
the user must be notified of the error and the same question prompt should be displayed (this should continue until
the users enter one of the correct selections):
Invalid selection! Please Try Again.
What would you like to do?
1. Find more than one occurrence of a character
2. Find character occurrence that has a vowel before it
Enter 1 or 2. (0 to return to main selection):
If a numeric 0 is entered, the program should return back to the main selection process. If any of the other valid
selections are entered, the program will then execute a standard process of collecting a character input and then
should execute the specific process selected. Each one of these process are defined further down in this
assignment. For each of those processes, a calculated result will be generated and returned to this section of the
program.
The “play with letters” section of the program has a predefined string used within the manipulation process. This
portion of the program needs to define and initialize this string prior to the manipulation processes. The string
should be initialized with the following sentence:
"The quick brown fox jumps over the lazy dog."
This string does not need to display to the user, but will be used in each of the selected processes and then the
results will be displayed to the user.
When the single calculated result is returned, the following prompt should be displayed with the results (where red
represents the numeric answer):
Your calculated result is: #####
After displaying the results to the user, the program should then re-issue the “Main Selection Process” prompt
listed above in the first section.
Explanation / Answer
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
int main()
{
const char *str = "TheQuickBrownFoxJumpedOverTheLazyDog";
int counts[26] = { 0 };
char vow[100];
int i,j,l,c=0;
size_t len = strlen(str);
int choice;
printf("enter 0:main choice 1: Find more than one occurrence of a character 2:Find character occurrence that has a vowel before it ");
scanf("%d",&choice);
while(choice<=2 || choice>=0)
{
switch(choice)
{
case 1:for (i = 0; i < len; i++) {
char c = str[i];
if (!isalpha(c)) continue;
counts[(int)(tolower(c) - 'a')]++;
}
for (i = 0; i < 26; i++) {
printf("'%c' has %2d occurrences. ", i + 'a', counts[i]);
}
break;
case 2:for(i=0;str[i]!='';i++)
{
if(str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u')
{
vow[j]=str[i-1];
j++;
}
}
l=j;
for(j=0;j<l;j++)
{
for (i = 0; str[i] != ''; i++) {
if (str[i] == vow[j])
c++;
}
printf(" Occurence of character '%c' : %d", vow[j], c);
}
break;
case 0:
printf("enter 0:main choice 1: Find more than one occurrence of a character 2:Find character occurrence that has a vowel before it ");
scanf("%d",&choice);
break;
}
printf("invalid choice");
printf("enter 0:main choice 1: Find more than one occurrence of a character 2:Find character occurrence that has a vowel before it ");
scanf("%d",&choice);
}
}