Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see a couple of issues with your implementation. First, you assume anything not a space is an alphabetic character. What about tabs, newlines, punctuation, etc? Secondly if two words are separated by just a newline, your code won't pick that up, since it only checks for words that are space delimited.</p> <p>The ctype.h header provides useful functions for determining if a character is whitespace, alphanumeric, punctuation, etc. See <a href="http://www.gnu.org/software/libc/manual/html_node/Classification-of-Characters.html#Classification-of-Characters" rel="nofollow">GNU C Manual - Classification of Characters</a> for more info. Something like the following should produce more robust results.</p> <p>Taking into account your comments in other posts that require a word to be more than two characters, the code becomes:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;ctype.h&gt; int main() { int w=0, v=0, c=0, cnt=0; int inword = 0; char *inp = "hi there, w w w here's\nmore than\none line.\nAnd contractions and punctuation!"; char ch; FILE *read, *write; write = fopen("character.txt", "w"); fprintf(write, "%s", inp); fclose(write); read = fopen("character.txt", "r"); if (read==NULL) { printf("Error opening file"); } while ((ch=fgetc(read))!=EOF) { if (isspace(ch)) { if (inword &gt; 2) { w++; } inword = 0; } else if (isalpha(ch) || ispunct(ch)) { inword++; if (isalpha(ch)) { c++; if (ch=='A'||ch=='a'||ch=='E'||ch=='e'||ch=='I'||ch=='i'||ch=='O'||ch=='o'||ch=='U'||ch=='u') { v++; } } } } if (inword &gt; 2) w++; printf("Character %d Vowel %d Word %d\n", c, v, w); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload