Thats the body of the while loop, no?
Ah, nvr mind. Moved ++i; to end of loop.
reads vowels now...
but i still am unsure on how to input more than once sentence
Thats the body of the while loop, no?
Ah, nvr mind. Moved ++i; to end of loop.
reads vowels now...
but i still am unsure on how to input more than once sentence
Last edited by rmrjr22; 11-13-2012 at 10:52 PM. Reason: needed to add more
This is what you wanted.
Code:while((sentence[i] = getchar()) != '\n') { if(sentence[i] == 'a' || sentence[i] == 'e' || sentence[i] == 'i' || sentence[i] == 'o' ||sentence[i] == 'u') { ++keystrokes; ++letters; ++vowels; } else { if (isalpha(sentence[i]) == 1) { ++keystrokes; ++letters; } else { ++keystrokes; } } i++; }
Fact - Beethoven wrote his first symphony in C
Or better yet...
Code:for(i=0; ((sentence[i] = getchar()) != '\n'); i++) { if(sentence[i] == 'a' || sentence[i] == 'e' || sentence[i] == 'i' || sentence[i] == 'o' ||sentence[i] == 'u') { ++keystrokes; ++letters; ++vowels; } else { if (isalpha(sentence[i]) == 1) { ++keystrokes; ++letters; } else { ++keystrokes; } } }
Fact - Beethoven wrote his first symphony in C
Or even better :P
Code:for(i=0; ((sentence[i] = getchar()) != '\n'); i++) { ++keystrokes; if (isalpha(sentence[i]) == 1) { ++letters; if(sentence[i] == 'a' || sentence[i] == 'e' || sentence[i] == 'i' || sentence[i] == 'o' ||sentence[i] == 'u') { ++vowels; } } }
Fact - Beethoven wrote his first symphony in C
So far this works great... minus being unable to input more than one sentence when the program runs
Code:#include <stdio.h> #include <stdlib.h> #include <ctype.h> int main(int argc, char *argv[]) { int keystrokes = 0; //Number of keystrokes. int letters = 0; //Number of total letters. int vowels = 0; //Number of vowels. int i = 0; char sentence[9999]; //Chararacter array specified to users input. while((sentence[i] = getchar()) != '\n') { if(sentence[i] == 'a' || sentence[i] == 'e' || sentence[i] == 'i' || sentence[i] == 'o' ||sentence[i] == 'u') //stating vowels { ++keystrokes; ++letters; ++vowels; } else { if (isalpha(sentence[i]) == 1) // if character is true { ++keystrokes; ++letters; } else { ++keystrokes; i++; } } } printf("SAMPLE OUTPUT, for EACH sentence above:\n"); printf(" Program#5 CS110.\n"); printf("Keystrokes %d \n", keystrokes); printf("Alpha Characters %d \n", letters); printf("Vowels %d \n", vowels); return 0; }
Works great, eh?Code:Hello friend SAMPLE OUTPUT, for EACH sentence above: Program#5 CS110. Keystrokes 12 Alpha Characters 5 Vowels 4
@Click_Here: Be careful of the return value of "isalpha()" - it might be better to just make sure it's true (or not zero), instead of equal to one.
Return value: A value different from zero (i.e., true) if indeed c is an alphabetic letter. Zero (i.e., false) otherwise.
I did rush it :P
Yes, that would be much better.
Looking at my sketch file where I copy/paste and run code for here, I seem to have done it before closing the file (?!) - I didn't repost the code though -> I remember now: I didn't think that it was worth reposting.
Your code is not working, because you are incrementing 'i' only if it's not a vowel and is not alpha. What is more annoying is that in a rare laps of judgement, I showed you where to do it in post 17Originally Posted by rmrjr22
Fact - Beethoven wrote his first symphony in C