/* Problem 5--Haiku This isn't too bad. Just read the string and count the syllables as specified. */ #include #include #include FILE *in, *out; int main (int argc, char **argv); int main (int argc, char **argv) { char line[201]; int L[3], l, v, i; in = fopen ("prob5.in","r"); out = fopen ("prob5.out","w"); while (fgets (line,sizeof line,in),line[strlen(line)-1]=0, strcmp (line,"e/o/i")!=0) { L[0] = L[1] = L[2] = 0; l = v = 0; for (i = 0; i < strlen (line); i++) { /* Is it a vowel? */ if (line[i]=='a'||line[i]=='e'||line[i]=='i'||line[i]=='o'|| line[i]=='u'||line[i]=='y') { if (!v) L[l]++; /* If previous letter was not a vowel, add one to */ v=1; /* the syllable count */ } else if (line[i]!='/') v=0; else { /* End of line; parse next one */ l++;v=0; } } /* Print out where the error is, if any */ if (L[0] != 5) fprintf (out,"1\n"); else if (L[1] != 7) fprintf (out,"2\n"); else if (L[2] != 5) fprintf (out,"3\n"); else fprintf (out,"Y\n"); } fclose (in); fclose (out); return EXIT_SUCCESS; }