Can someone please help me in understanding the mistake I am doing? I've got the segmentation fault in the terminal window after running the program and providing the text.

Here is my code ... enter image description here

and this is what I am getting... enter image description here


There's no use for isalnum (alphanumeric) here. isalpha might have some value.

Your mistake is probably in isalnum(text = 0). This code will set text to NULL, and then check whether NULL (then interpreted as '\0') is an alphanumeric character, which it isn't. But after that line, any access to characters in text will fail, likely causing a segmentation fault.

You are overcomplicating stuff when counting words and sentences. The problem description clearly states

any sequence of characters separated by spaces should count as a word, and that any occurrence of a period, exclamation point, or question mark indicates the end of a sentence.

Also, check the "hints".

  • Thank you so much for your help. It worked! Mar 3 '20 at 5:47

You must log in to answer this question.

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