how to add our own function in c library please give details.?

Answer Posted / sevak.yatrik777

There are a few ways to do this.

Write the code with a proper header file and compile to an
object file. You only need to include the header in your
code and tell the compiler where to find the object file. In
most cases, you can combine functions in object files to
create a larger library object file. Note that once you
compile to an object file, it may also be included for use
with other compiled programming languages. You can do this
with some Microsoft compilers and some Gnu based compilers
under Linux but you can't mix Gnu and Microsoft. You could
mix Quick BASIC and Microsoft C, Some versions of Visual
Basic and Visual C/C++, Basic/Pascal/Delphi/C/C++, and gcc
and other gcc based languages if the languages have the
extras to deal with alternate styles of passing arguments as
needed. You may need to include something like CDECL for
declaring functions in other languages. This can be a
multiple step process if you are compiling using more than
one programming language.

A second option is write your code with a proper header
file. Copy the library code to the work directory for the
project and compile as you would for any other multiple file
project. This assumes you are only using compatible C or C++
compilers.

A third option is you compile the library to object code
using the compiler for the project. This is common practice
for special math libraries and other library packages. You
only need to include header files and the location of the
object files in your main project like in option 1 though it
is more or less option 2 done in two steps. Many of the free
libraries are available this way.

I generally go with the second or third option as I use
several compilers and if it is a serious project, I'm
usually using C or C++ anyway. Some of my "library" files
contain special defines so they actually work with alternate
compilers. With a bit of research, you can often auto detect
the compiler from internal compiler specific defines. While
auto detcting compilers is a bit of extra work, your library
functions are virtually drop in and don't require any extra
work when you use them.

In the end, do what ever is best for your own projects.

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the use of bit fieild.

717


What are the standard predefined macros?

639


What is pointer to pointer in c?

637


Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?

602


What is the use of parallelize in spark?

582






why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above

615


Why is c platform dependent?

627


An application package has been provided to you without any documents for the following application. The application needs to be tested. How will you proceed?

676


What is data types?

643


How will you print TATA alone from TATA POWER using string copy and concate commands in C?

922


the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters

1807


In which language linux is written?

607


Explain how do you use a pointer to a function?

642


develop a breakfast order booking system using Functions, Structures and Arrays. The system is to support the operations shown to the user in the following system’s menu: Welcome to Asim's Restaurant Select an operation? 1 Make a breakfast order 2 Modify existing order 3 Cancel existing order 4 Print Bill 5 Exit Type in your selection (1, 2, 3, 4 or 5): The program will include an array of structures. The structure type is called MenuItem, and the array of structures should be declared as menu[50] to store upto 50 breakfast menu items. The MenuItem structure must have the following 4 data fields (i.e. members): Code, description, unitprice, and quantity. Your program must define at least the following functions:  Function LoadData(…) that loads the data of breakfast menu items from an input file menu.txt into the array menu.  Five separate functions to handle the program main menu five tasks shown above. In general, function main() should load the data into the array menu and display the main menu of the above mentioned tasks. Based on the option selected, the corresponding function should be called. Users must make an order before requesting modify, cancel or print order bill (See the given sample run). Here is a more detailed explanation on the above tasks and functions. LoadData(…) Opens the input file menu.txt (you will create it) containing breakfast menu items data (See below) and assign these values to the corresponding array menu structure fields. Assign zero to the quantity field of the loaded menu items. Welcome to Asim's Restaurant Select an operation? 1 Make a breakfast order 2 Modify existing order 3 Cancel existing order 4 Print Bill 5 Exit Type in your selection (1, 2, 3, 4 or 5): MakeOrder(…) This function is called when the user selects option 1 from the main menu. It first displays the breakfast menu items to the user (stored in the array menu) along with all the necessary information (item code, description and unit price). It then requests the user to select an item using the item code (see the sample run). When the user enters an item code number the program should verify the code number and increment the quantity of the selected item in the array menu. Your program should reject invalid item codes and request the user to re-enter the item code or stop the entry. PrintBill(…) This function is called when the user selects option 4 from the main menu. The function displays the breakfast menu items in the breakfast order by printing the values of all MenuItem members of the array menu that have quantity value above zero. Print a nicely formatted bill (See the sample run). CancelOrder(…) This function is called when the user selects option 3 from the main menu. It will cancel the breakfast order by setting the quantity value of all the array menu structures to zero. ModifyOrder(….) This function is called when the user selects option 2 from the main menu. The task of this function is to allow the user to edit an existing breakfast order with two operations: Adding more breakfast items and/or altering the breakfast item that were ordered before (examine the sample program run). Handling Errors and Invalid Input Your program should reply safely to any erroneous situation or input with appropriate message to the user and flow nicely and correctly to the next operation (Examine the sample program run). Additional functions Use of functions is highly recommended for any additional special tasks needed by your solution. Global variables are not allowed except for max array menu size 50. You must pass the needed parameters through functions parameter lists.

1971


int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above

759