I need that the user can only enter 1 letter and only lowercase or capital (not numbers, not signs – only letters), and otherwise the program ended.
How do I spend this check?
In the code you need to check only the variable Letter
int main () {
Char Letter = 0;
Char char_sequence = 0;
int TIMES_LETTER_REPEAT = 0;
PrintF ("Enter Letter to Count: \ N");
Scanf ("% C", & amp; letter);
Printf ("ENTER THE CHAR SEQUENCE: \ N");
Scanf ("% C", & amp; char_sequence);
While (char_sequence! = '$')
{
if (char_sequence == letter || char_sequence == letter - 'a' + 'a') {
TIMES_LETTER_REPEAT ++;
}
Scanf ("% C", & amp; char_sequence);
}
PrintF ("The Letter Appeared% d Times \ N", Times_letter_repeat);
Return 0;
}
Answer 1
CHAR S [2];
if (scanf ("% 1 [a-za-z]", s)! = 1) exit (1);
char ch = * s;
Answer 2, Authority 100%
not numbers, not signs – only letters
man 3 isalpha
isalpha () - Checks for an alphabetic character;
Answer 3
# include & lt; stdio.h & gt;
# INCLUDE & LT; Ctype.h & gt;
INT MAIN (Void)
{
// only the alphabet takes.
// counts only
// One specified letter.
// To exit, enter any non-link symbol.
// For processing Cyrillic Add & lt; wctype.h & gt;
// respectively change the view
// on wchar_t and the names of functions for example iswalpha ()
Char Let, Charseq;
int letcount = 0;
PrintF ("Enter Letter to Count: \ N");
Scanf ("% C", & amp; let);
Printf ("ENTER THE CHAR SEQUENCE: \ N");
While (SCANF ("% C", & amp; charseq) == 1)
{
if (ISDIGIT (CHARSEQ) || ISPUNCT (CHARSEQ))
Break;
if (isalpha (charseq))
{
if (charseq == let)
LetCount ++;
}
}
Printf ("The Letter Appeared% d Times \ N", Letcount);
Return 0;
}