Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 6, 2013, 09:47 AM   #1
007bond
macrumors 6502a
 
007bond's Avatar
 
Join Date: Dec 2008
Location: DFW, Texas
Basic C Programming Question - Can anyone help?

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
__________________
New: Nexus 4 16GB
iPhone 5 16GB Black & Slate; iMac 27" 2009; Canon Digital Rebel XT(Silver)!; 2012 MacBook Air 13" 1.8GHz Core i5 w/ 4GB RAM, 128GB SSD

Last edited by balamw; Feb 6, 2013 at 12:16 PM. Reason: QUOTE->CODE
007bond is online now   0 Reply With Quote
Old Feb 6, 2013, 10:25 AM   #2
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Seattle, WA
You need to give scanf the address of an int so scanf can set its value. Pass &count rather than count.

-Lee
lee1210 is offline   0 Reply With Quote
Old Feb 6, 2013, 11:29 AM   #3
007bond
Thread Starter
macrumors 6502a
 
007bond's Avatar
 
Join Date: Dec 2008
Location: DFW, Texas
Quote:
Originally Posted by lee1210 View Post
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!
__________________
New: Nexus 4 16GB
iPhone 5 16GB Black & Slate; iMac 27" 2009; Canon Digital Rebel XT(Silver)!; 2012 MacBook Air 13" 1.8GHz Core i5 w/ 4GB RAM, 128GB SSD
007bond is online now   0 Reply With Quote
Old Feb 6, 2013, 12:15 PM   #4
LPZ
macrumors 65816
 
Join Date: Jul 2006
Quote:
Originally Posted by 007bond View Post
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]"
LPZ is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 10:43 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC