• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

A rather simple question

L337Llama

Senior member
So, for a project I have due today at 3:30, I wrote it in C. First time I've used C, all my work to this point has been in Java using bluejay or eclipse. Anyway, I got it written and i want to see if it actually works, and I got to no clue to how to compile and run it. I've been spoiled by having a giant compile button in blujay and just right clicking a class and running methods in it.

I've tried looking around and searching stuff on google, but I ended up with a lot of stuff from pre-2000.

Thanks a lot.

*also, I wrote in HAM if that helps.
 
Here is what i've written. It's supposed to be a simple calculater that takes an input like 4*3 and performs it, and returns an error if its not int char int, and halt the program if it recieves q as the input. I still have to add a thing where it saves a history of all the functions performed to a string that gets output when the programing is halted, but I wanna make sure the rest of it works before I try that. I have a blank header file since I didnt need to set any values or load stuff.

int main(void)
{
int int1 = 0;
int int2 = 0;
char func1[4];
char in1[20];
int run = 0;
double solution;
int scanSuccess;

while (run == 0)
{
scanSuccess = 0;
gets(in1);
scanSuccess = sscanf(in1, %d %s %d, &int1, func1, &int2);


if (strcomp(in1,"q") == 0)
{
int run = 1;
}

else if ( scanSuccess == 3)
{
else if (strcomp(func1,"*") == 0)
{
solution = int1 * int2;
printf("%d * ", int1);
printf("%d = ", int2);
printf("%f\n", solution);
}

else if (strcomp(func1,"-") == 0)
{
solution = int1 - int2;
printf("%d - ", int1);
printf("%d = ", int2);
printf("%f\n", solution);
}

else if (strcomp(func1,"/") == 0)
{
solution = int1 / int2;
printf("%d / ", int1);
printf("%d = ", int2);
printf("%f\n", solution);
}

if (strcomp(func1,"+") == 0)
{
solution = int1 + int2;
printf("%d + ", int1);
printf("%d = ", int2);
printf("%f\n", solution);
}
}

else
{
printf("Error\n");

}

}
printf("Found Q, gonna stop running.\n";
return 0;
}
 
What tools do you have access to? You can compile a C source file in Visual Studio, or using GCC (the Gnu C/C++ compiler). I don't remember the exact command line for GCC, but you pass it the .c source and specify the name of the resulting .obj, and you also need to specify the runtime libraries the linker needs. Usually this is all done via a makefile.
 
I got it to compile. I downloaded cygwin and ran gcc through that. However, when i try running the exe it made, I get an error message about needing cygwin1.dll. I downloaded a copy of the dll file, but I dont know where to install it.
 
Originally posted by: L337Llama
I got it to compile. I downloaded cygwin and ran gcc through that. However, when i try running the exe it made, I get an error message about needing cygwin1.dll. I downloaded a copy of the dll file, but I dont know where to install it.
For now, put the dll in the same directory where your application is.

 
For Visual C++ or Visual Studio, start by opening the cmd window that comes installed in the Visual Studio Tools menu (the Command Prompt). Then run cl foo.c which produces foo.exe. Of course your code above will need to #include <stdio.h>, and possibly <stdlib.h> before it will compile.

Plus it looks like you have a small issue with the sscanf (the parameter string should be quoted), and the bracketing on the if/else statements needs to be fixed a bit.
 
Back
Top