Basic C Programming Question - Can anyone help?

Discussion in 'Mac Programming' started by 007bond, Feb 6, 2013.

  1. 007bond, Feb 6, 2013
    Last edited by a moderator: Feb 6, 2013

    macrumors 6502a

    007bond

    #1
    This is part of my code:

    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:
    Code:
    7
    jones
    smith
    aki
    ren
    stimpy
    bart
    Simpson
    
     
  2. macrumors 68040

    lee1210

    #2
    You need to give scanf the address of an int so scanf can set its value. Pass &count rather than count.

    -Lee
     
  3. macrumors 6502a

    007bond

    #3
    Wow...I feel really stupid right now. Thanks for the help!
     
  4. LPZ
    macrumors 65816

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

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

Share This Page