PDA

View Full Version : Basic C Programming Question - Can anyone help?




007bond
Feb 6, 2013, 09:47 AM
This is part of my code:


int main(){

char str[100];
char min[100];
char max[100];
int count;
int num = 0;

scanf("%i", count);


On the line with "scanf", I get the error " warning: format ‘%i’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat]" (I'm using a unix-based compiler, if that helps).

I'm reading in data from a file with this data:

7
jones
smith
aki
ren
stimpy
bart
Simpson



lee1210
Feb 6, 2013, 10:25 AM
You need to give scanf the address of an int so scanf can set its value. Pass &count rather than count.

-Lee

007bond
Feb 6, 2013, 11:29 AM
You need to give scanf the address of an int so scanf can set its value. Pass &count rather than count.

-Lee

Wow...I feel really stupid right now. Thanks for the help!

LPZ
Feb 6, 2013, 12:15 PM
Wow...I feel really stupid right now. Thanks for the help!

Well, the error message was pretty spot-on. :)

"warning: format ‘%i’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat]"