Hey.
Here is alittle bit of my code.
I keep getting some weird numbers such as 66732 when it prints and obviously i am only putting in a 4-5 letter word.Code:char words[MAX_SIZE]; /* array of words */ int totalLetters; printf("%d\n", calcSize(words, &totalLetters)); /* print value of function calcSize*/ int calcSize(char words[], int *totalLetters) /* function calcSize */ { int sum = 0; int i =0; while(words[i] != '\0') { for (i =0; words[i] ; i++) *totalLetters++; } return *totalLetters; }
What i am trying to do is everytime i run a word through this calcSize() function, to count the totalLetters of that word and return the totalLetters, but next time I call the function I want totalLetters to still hold the new value. So if i had 2 words: Hello world, at the end of the 2 calls , totalLetters should return 10.
Im just starting to use pointers so i suspect the problem is related to them.
Thanks
PS. title should probably be Call by reference.