-
Create a Main file
Hi, i am new to C language. Yesterday was my first day.
I have to small programs. One that converts Fahrenheit to celsius in 20 degree increments and one that does it in 15 degree increments. they work fine but i was playing around with it and i wanted to make a Main file that calls both of them and displays the results.
here is how my files look.
Code:
#include <stdio.h>
/* convert Fahrenheit to celcius in steps of 20*/
int steps = 20; //increment steps
Code:
#include <stdio.h>
/* convert Fahrenheit to celcius in steps of 15*/
int steps = 15; //increment steps
this is the main.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <f_to_c.h>
#include <f_to_c2.h>
int fahr;
int cels;
int min = 0;
int max = 300;
main() {
fahr = min;
while(fahr <= max){
cels = 5 * (fahr - 32) /9;
printf("%d\t%d\n", fahr, cels);
fahr = fahr + steps; //increment fahrenheit by 20 degrees
}
}
when i run this, i get some error messages.
Main.c:10:20: f_to_c.h: No such file or directory
Main.c:11:21: f_to_c2.h: No such file or directory
Main.c:26: error: `steps' undeclared (first use in this function)
Main.c:26: error: (Each undeclared identifier is reported only once
Main.c:26: error: for each function it appears in.)
thank you in advance
-
I suppose that f_to_c.h and f_to_c2.h are placed on the same main.c file's folder. To include them you should specify the path (relative or absolute) to the files instead the realtive path to the compiler include's folder (or maybe you can configure you compiler to have also a look at you folder as it was part of the include folder):
Code:
//#include <f_to_c.h>
#include "f_to_c.h"
Note: since the main code have 'stdio.h' included, you don't need to include it on the auxiliar headers (or since you have included 'stdio.h' in your aux headers, you don't need to declare in the main code).
Hope that helps
Niara
-
You'll just need one file, and have just one int main() function. That function should call your two other functions:
Code:
#include <stdio.h>
//I doubt that you should keep all these, as globals, but for now, ok
int fahr;
int cels;
int min = 0;
int max = 300;
void FtoCby20(void); //the functions definitions or prototypes
void FtoCby15(void);
int main(void)
{
int gar;
FtoCby20();
FtoCby15();
printf("\n\n\t Program Complete Press Enter When Ready ");
gar = getchar(); gar++; //holds the console window open, and stops warnings
return 0; //normal program termination has occurred
}
void FtoCby20(void)
{
//add your code for this function, here
}
etc.
Hope that helps.