Question

How can I use Dev C++ to compile C source file. I thought it would automatically do it, but for some reason it compiles with several errors and I think its because you have to make changes for it to compile a C file.

Example test code:

 #include <stdio.h>



main ()        
{ int i,j;
double x,x_plus_one();
char ch;

i = 0;
x = 0;

printf (" %f", x_plus_one(x));
printf (" %f", x);

j = resultof (i);

printf (" %d",j);
}


double x_plus_one(x)          

double x;

{
  x = x + 1;
  return (x);
}


resultof (j)             

int j;

{
   return (2*j + 3);       
}
Was it helpful?

Solution

That is pre-ANSI code. I'm not sure the gcc compiler supports it, and in any case it is bad practice to use it. Change your function to:

double x_plus_one( double x) {
  x = x + 1;
  return (x);     
}

and you will need to declare it as:

double x_plus_one( double x);

You may also want to try compiling with the -traditional flag, but I haven't tested this.

OTHER TIPS

Change main to int main() as well. And Do the modification as Neil pointed out.

i think you were trying to write this:

#include <stdio.h>

double x_plus_one(double x);
int resultof(int j);


main()        
{ int i,j;
double x;//,x_plus_one;
char ch;

 i = 0;
 x = 0;

printf (" %f", x_plus_one(x));
printf (" %f", x);

j = resultof (i);

printf (" %d",j);
}


double x_plus_one(double x)

//double x;

{
  x = x + 1;
  return (x);
}


int resultof (int j)             

//int j;

{
   return (2*j + 3);       
}

save as main.cpp and for compiling

g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/Program Files/CodeBlocks/MinGW/include" -g3

g++.exe -D__DEBUG__ main.o -o Project1.exe -L"C:/Program Files/CodeBlocks/MinGW/lib" -static-libgcc -mwindows -g3


Compilation results...
--------
- Errors: 0
- Warnings: 0
- Output Filename: F:\My Folder\C++ projects\test01\Project1.exe
- Output Size: 38.990234375 KiB
- Compilation Time: 1.92s
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top