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.
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
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".