0

How do I count the character apostrophe ( ' ) in a sentence. When I tried: if (s[n] == (''') error message showed "expected expression". missing terminating ' character. Other characters counting were fine without showing error messages.

0

Is this for readability?? if it is then don't bother reading it just create conditions for letters, words, and punctations for sentences don't use an else statement, so when your program reads an (') it will just do nothing with it and move on to the next index.

1
  • Good suggestion.
    – jkleong
    May 4 '20 at 23:36
0

Remember, that quotes, either single ' or double " must come in matched pairs. This sentence

 if (s[n] == (''')

has only 3 single-quotes '. Since s[n] is a char, the desired char must be enclosed in single quotes. Therefore the quote character must be "escaped". In C \ is the escape character. It means "read the next character literally". So the sentence if (s[n] == ('\'') will compile and will compare the character to '.

This is meant as an explanation of the error; the advice in the (current) other answer is sound and describes why this if could be deemed unnecessary.

1
  • Nice to know that there is an escape character to use.
    – jkleong
    May 4 '20 at 23:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .