C Program Trouble Compiling w/GCC, Trouble Running in Xcode

Joined
Jan 14, 2009
Messages
6
Reaction score
0
Points
1
I wrote a C program that worked perfectly in Windows, but I am having trouble using Mac OS. In Windows I used DevC++ to compile and run the program.

When I tried to compile it in Xcode, it gave me an incorrect output. It kept giving me "inf" and "nan" for what I'm assuming is "infinite" and "not a number." It seems like it's not correctly calculating "eta" on line 121 of my source code (attached).

I thought it might be a compiler problem so I tried to compile it from the command line using gcc. I used the command:

gcc SLP.c -o SLP

It would not compile. This is the error I would get:

SLP.c:1:19: error: stdio.h: No such file or directory
SLP.c: In function ‘main’:
SLP.c:41: warning: incompatible implicit declaration of built-in function ‘printf’

It seems like there is a problem with my OS recognizing the stdio.h library. I've never had a problem with any C program with Xcode before. I did recently reinstall Xcode with the iPhone SDK. I want to reiterate that my program ran fine with DevC++ on Windows.

I've attached my code in case anyone wants to look at it. I had to attach it as a text file because a .c file would not upload. Just change the file extension. The correct final outputs should be w(0) = -4, w(1) = 2 and w(2) = 3.

View attachment SLP.txt
 
Joined
May 2, 2009
Messages
480
Reaction score
13
Points
18
Your Mac's Specs
MBP 2.33 4GB: MacPro 8 Core 2.8, 16GB: MacMini 2.26 4GB: MacMin 2.53 4GB: iPhone3GS 32GB
I had no issues compiling and running your code via the command line or in XCode so it seems like your environment may be at issue from the CL. Also, you need to declare

#include <stdlib.h>

to allow the abs function to be within the compilation scope to get the correct output. If you add this you should be all set.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top