using header files: how do you ref and put fumulas in headers files
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
/*
*
*/
int main() {
int selection;
double temperature;
double conversion;
printf("1 - Fahrenheit to Celsius\n");
printf("2 - Celsius to Fahrenheit\n");
printf("-------------------------\n");
printf("Your selection is?: ");
//Selection from user
scanf("%d", &selection);
if( selection ==1 || selection ==2)
{
printf("Please enter the temperature you would like to convert: ");
//Scanning in the temperature
scanf("%lf", &temperature);
In theory you do not do the implementation in header files. Of course you can always have an exception, for example when your function do only one very trivial thing like an assignment, or just one mathematical operation.
So what you should do is to define the .c file. For example, for cent_to_fahr.c:
Code:
#include "cent_to_fahr.h"
double cent_to_fahr(double temp)
{
/* put your implementation */
}
And just for your information, if your code is some C code, I think that you should remove "using namespace std;" line in your code
So if you don't put the fomula inside the header file what do you use the header file. Not really understanding how or why you would use a header file. For such simple programs why would you need a header file?
I remove the < > from the program in the include. But I not understanding header files, I was given the header file and told to use them in the program in the conversion. Not really sure how to implement. I read your secound post and I am still confuse. As you can probably tell I am new to programming.
So if you don't put the fomula inside the header file what do you use the header file. Not really understanding how or why you would use a header file. For such simple programs why would you need a header file?
For such a simple program, it is true that the interest is quite limited. But headers are really to create a clean separation between declaration and implementation. A typical example is library. When you use a library to link with your program, you just need header files and the .so (shared object) file. The headers contain the declaration of available functions of your library and the .so file the binary code (compiled implementation).
So in your specific case, you would have a "libconvert_temp.so" generated from "cent_to_fahr.c" and "fahr_to_cent.c" files and the headers. And when you create your program, you just have to include the correct headers, and then link your program with "-lconvert_temp".
I remove the < > from the program in the include. But I not understanding header files, I was given the header file and told to use them in the program in the conversion. Not really sure how to implement. I read your secound post and I am still confuse. As you can probably tell I am new to programming.
Since you say you were given the header file, I am guessing this is an assignment of some kind.
Header files are used to share information across multiple files and to organize your declarations. In this case the header files contains some defines and declarations for some functions.
I expect you are expected to provide the implementation for those functions. Possibly in files of there own.
If that is the case you could create 1 or 2 more files containing the conversion functions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.