R
R
Reslyukov Alexander2020-12-08 15:55:25
C++ / C#
Reslyukov Alexander, 2020-12-08 15:55:25

How to count the number of consonants surrounded by numbers in C language?

Task: "Count the number of consonant letters of the string s, which are surrounded by numbers on both sides."
I thought somehow using a cycle to assign some value to each character, and then using another cycle to work with these values. Roughly speaking, if some a="one of the consonants" and at the same time a-1 and a+1 ="any number", then the variable b, which will be the number of such letters, increases. In words, it may be so, but in reality I do not understand how it should look like.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
ComodoHacker, 2020-12-08
@ComodoHacker

I would make a "character class" enum with the values ​​vowel, consonant, digit, etc.
In the loop, we define the classes of the current, previous and next character. Further, I hope, it is obvious. :)

R
res2001, 2020-12-08
@res2001

And in deeds as well as in words.

somehow using a loop to assign some value to each character

Everything has already been assigned for a long time, nothing needs to be invented. It's called ASCII Table, google it.
But in fact, there are functions in the C standard library that check for a character and return this letter, number, or something else. You can start from here: https://en.cppreference.com/w/c/string/byte/isalpha
At the bottom there is a table comparing all such functions.
You will only have to correctly set the localization before using these functions, because. with the wrong locale, there may be problems with the recognition of Russian letters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question