warning: comparison between pointer and integer
Hello all,
I'm still quite new to programming, and are merely trying to create a program to calculate and display the Sum and Average of an array of values. However, when I compile I get the Error: AverageWorking1.c:43:6: warning: comparison between pointer and integer AverageWorking1.c:43:15: warning: comparison between pointer and integer Line 43: if (n>100 || n<2) Code:
#include <stdio.h> |
Exactly what it says on the tin! "n" is a pointer...
Quote:
Code:
if (*n>100 || *n<2) |
so n is a pointer. It holds the location in memory where a value lives. n does NOT contain the number. It "points" to where a number is.
To make this work, the if statements shoudl just be changed to reference "*n" instead of "n", but I would personally look to make GetUserInput(int* n) take the n directly instead (your &n when calling it creates the pointer reference) so tweaks like: if(GetUserInput(&n)) ---> if(GetUserInput(n)) GetUserInput(int* n) ---> GetUserInput(int n) temp = scanf("%d", n); ---> temp = scanf("%d", &n); etc. Note that you've used scanf differently here, once time you give it the variable, num, the other you create a pointer reference from n, &n. |
Ah, of course!
Thank you for all the help! I feel such a fool, but I am still getting used to pointers. :L -Mr Oblivion |
All times are GMT -5. The time now is 01:26 AM. |