Simple C If Statement -
I have created a very simple program that how many characters and words are counted in a string (I how many spaces Are in the text and have to check one). The current code is low (to keep it short 'without printf):
int main (int argc, char * argv []) {int character; Int word, character = 0; While ((character = getchar ()) = '\ N') {character = ++ characters; If ((character == '') || (character == '\ d')) {words = ++ words; }} Return 0; } My problem is that the counting words do not work. I get an exact number for the characters, but the word always gives me 22 9 3576, and why I do this for the world can not do.
Can anyone solve this mystery for me?
All your answers; I really appreciate the help.
And sorry if my ancient skills hurt some of your head I'm making a start, but hopefully there will be improvement in speed.
You words Undefined local variables are not initialized for an undefined value in default and automatically on zero. Statement
int x, y = 0; It is not
int x = 0, y = 0;
Comments
Post a Comment