Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cathy88

macrumors member
Original poster
Aug 11, 2009
95
0
Hey, Ive been doing some c language at school but it was to do with microprocessors, anyway Im wondering if its possible to compile my code into .exe excutable so Windows command window could be used. I know C++ can I think from memory but Im really unsure could someone point me into a direction on how or what to read? Below is my code

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
int minNum=0;
int maxNum=100;
srand ( time(NULL) );
int num=rand()%100;
int count=0;
int guessNum;
printf("Number Guessing Game\n\n");
printf("Guess a number between 0 to 100\n");
while(1)
{
scanf("%d",&guessNum);
if (guessNum != num && guessNum > num && guessNum<=100) {
printf("The number is between %d to %d\n",minNum,guessNum);
maxNum=guessNum;
count++;
}
else if(guessNum != num && guessNum < num) {
printf("The number is between %d to %d\n ",guessNum,maxNum);
minNum=guessNum;
count++;
}
else if(guessNum >100){
printf("Please enter a value within the range %d is not within the range of 0-100\n",guessNum);
}
else if(guessNum==num){
count++;
break;
}
}
if (count==1) {
printf("YOU WON! the number is %d took you %d guess\n",num,count);
}
else{
printf("YOU WON! the number is %d took you %d guesses\n",num,count);
}
return 0;
}
 
Sure just install Mingw on Windows and then compile it there.

There maybe a solution for Mac OS X but if there is I have never heard of it. I imagine it is far easier to install Windows in VirtualBox and then compile it there than it is to get a working tool chain that produces Windows executables.

Although having said that if you only use the standard library it might work if you get GCC to spit out ASM and then use NASM to assemble it as a Windows executable. I know if you compile NASM yourself it supports most binary formats.

Edit: I'm not sure if GCC can output Intel style ASM or even if it is in a NASM compatible syntax.
 
Sure just install Mingw on Windows and then compile it there.

There maybe a solution for Mac OS X but if there is I have never heard of it. I imagine it is far easier to install Windows in VirtualBox and then compile it there than it is to get a working tool chain that produces Windows executables.

Although having said that if you only use the standard library it might work if you get GCC to spit out ASM and then use NASM to assemble it as a Windows executable. I know if you compile NASM yourself it supports most binary formats.

Edit: I'm not sure if GCC can output Intel style ASM or even if it is in a NASM compatible syntax.

Hey thank you for the help, Im just programing for fun starting with something very small ( a stupid guessing game:D). Anyway mind explaining what NASM or ASM means and or how it could be used in command window?
Meanwhile Ill try the program suggested for Windows.

Thanks

edit:

Im at the site there is all these files Im not quite sure which I need and which I dont need, would you mind giving a hand on which I should download?
http://sourceforge.net/projects/mingw/files/

Thanks again
 
hi, i compiled it on my mac, i couldnt get whats the exact problem you have?
i am using xcode tools.

She wants to compile it for Windows not Mac OS X. That is the issue.

Im at the site there is all these files Im not quite sure which I need and which I dont need, would you mind giving a hand on which I should download?
http://sourceforge.net/projects/mingw/files/

Thanks again

Sure. Download the Installer from here. Get version 5.1.6.
 
Ive donwloaded and installed it but was unsure of what to do, then I also installed cygwin and c compiler and compiled the file on windows, it came out as .exe but when I click it it wont open gives an error, what am I suppose to do?

Thanks
 
Ive donwloaded and installed it but was unsure of what to do, then I also installed cygwin and c compiler and compiled the file on windows, it came out as .exe but when I click it it wont open gives an error, what am I suppose to do?

Thanks

If you want to make a .exe file that you can simply click to run you need to use Microsoft Visual Studio. The executable file created by gcc or g++ with cygwin creates a unix executable. If you want to run what you compiled with gcc or g++, go to the directory where the file is located (do this in cygwin) and the type "./program" without the quotes where program is your program name.
 
Just to make sure we're understanding you correctly: you want to compile a program on your Mac which can be run on a Windows system?
 
If you want to make a .exe file that you can simply click to run you need to use Microsoft Visual Studio. The executable file created by gcc or g++ with cygwin creates a unix executable. If you want to run what you compiled with gcc or g++, go to the directory where the file is located (do this in cygwin) and the type "./program" without the quotes where program is your program name.

You don't need to use Visual Studio to make a program that can be 'double-clicked' on. A program compiled in the cygwin environment (with cygwin gcc) will run outside of the cygwin environment and by just double clicking on it from within windows explorer. That's what the cygwin1.dll file is for ... to make it run. You can also run the program on a windows computer that does not have cygwin installed as all as long as you distribute the cygwin1.dll file along with it. Same goes for things compiled with mingw/msys except you need to distribute the mingw dll file along with.
 
You don't need to use Visual Studio to make a program that can be 'double-clicked' on. A program compiled in the cygwin environment (with cygwin gcc) will run outside of the cygwin environment and by just double clicking on it from within windows explorer. That's what the cygwin1.dll file is for ... to make it run. You can also run the program on a windows computer that does not have cygwin installed as all as long as you distribute the cygwin1.dll file along with it. Same goes for things compiled with mingw/msys except you need to distribute the mingw dll file along with.

Right. I meant to create a .exe file that will execute on any Windows machine without other files needed.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.