how to call functions

Posted on 2000-03-17
Medium Priority
Last Modified: 2010-04-15
Hello All,

I am programming an application for a handheld   computer  that has a barcode scanner as a peripheral device,  I have obtained the software Dev Kit from the manufacturer, and it contains all the header files and libraries to operate any approved periphs for the unit.

My question is this:  how do I call the functions from the header files and or libraries to enable this unit to scan barcodes?  I belive the process  goes  somewhat like  step1) Initialise scanner
step2) get scanned data step3) uninitialise scanner.    I am  currrently waiting  on more  information from the Dev Kit manufacturer  but  would  like  to begin  tryin  some  ideas.
As you can probably tell,  I am very new at C programming,  so any extra detail you can spare  will go a long  way  and  be very appreciated.  For the record,  the Development environment is a package  called "Penright!"   and  it is  a visual IDE  that  allows  custom C code to be added.
Bottom  line......how  do I call functions in my header files?   what  do I look for? what  is the syntax?   what errors  will I receive  if  I do it wrong?   I know  this  is a potentially  endless question,  and  I dont  expect  a C tutorial....but   a little  guidance and  a little  overview  would  be great.   Thanks  in Advance  

Question by:DaveMon
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +4

Expert Comment

ID: 2628659

The first thing that you need to do is to include the header file at the top of your code:

Then you have to find out the names of the functions that are contained in the header file.

Then you should note what parameters are necessary to call the funcion.

For example if the function in the header file is called:

int function1(int num1, int num2)

This function is called function1 it has two integer parameters (num1, num2) and it returns an integer.
So in your code you can call it like this:


int integer1
int integer2
int integer3
integer3 = function1(integer1, integer2)
This would call function1 using integer1 and integer2 as parameters and return answer into integer3.


Expert Comment

ID: 2628675
Also all code contained in the brackets of the main function should end with ;
LVL 14

Expert Comment

ID: 2628887
I don't reply to you Q about Function :
homer99 said basic things, other see
in every C/C++ tutorial. But about scanning barcode:
I risk to answer, becouse i have made same system(work
name: Shop). And reply is very simple: you don't need
make anything! Detailes:
You use plug-in cable of keybord and set it in Scaner.
You use plug-in cable of Scaner and set it in Computer.
Now: if user presses key on the keybord, key simple
go to computer , but if user scans a Barcode, you get
Input : some digits( 1234567890123 for example,
usually 13 digits) . You programm in this moment
is in BarCode Contol and treats it (my, for example,
get data about Products from DataBase and display
name of product,price...).
Question: what will be, if you in other Control(for example
in name of product) and user scans a Barcode? For protect from this, i test Name of product : can't be all digits!

I hope, it helps. Alex

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 2628908
I appreciate the help alex,   but  the  unit  in question  has  no  keyboard,  only  a touch  panel,  and I am using  one companies  software  to make  another  companies hardware work ( with the aid  of  their  libs  and  header  files )....while  Im  here.....Homer  could you tell me basically, how  I would  call the function in this header   file?    

// SCAN is the scanned data from the read routine
// Reading is this converted to ASCII
// Both routines remove start and stop sentinels from the data

#include "SCNTST.h"

// 6 bit data TEXT and Numeric
int decode_track1 (char *reading, char *scan);

// 6 bit data Numeric only (and separators)
int decode_track2 (char *reading, char *scan);

// This routine calculates the length of the barcode data
int data_length (char *buffer);


again,  all I need  are  basic  guidelines  as  to how  these  calls  are made  in code


Expert Comment

ID: 2629373
there are three functions declared in the header file:

int decode_track1 (char *reading, char *scan);
int decode_track2 (char *reading, char *scan);
int data_length (char *buffer);

for example, in your C code:

int nReturnVal;
int nDataLen;

char szReading[1024]; // define this however big you need it to be...
char szScan[1024];   // same here...

you would like to see the user documentation on how these functions are actually used, however...
nReturnVal = decode_track1(&szReading, &szScan);

nDataLen = data_length(&szScan);

Expert Comment

ID: 2629489
You tell your program what procedures you are going to use by putting
near the top of your program, just like homer said.

You call the procedures just like you would call a procedure that you wrote.

You also will have to tell the linker to include the object file that contains the procedures.  It will look something like procedures.o
You didn't say what compiler you are using so no one can tell you the exact command.

Expert Comment

ID: 2630643
Hi Dave
The above mentioned steps are alright.
 it will be nice if you have all your header files in one directory and then give the path for library searching as that directory's path.Otherwise sometimes you get an error saying that library not found or something similar to that.
LVL 14

Accepted Solution

AlexVirochovsky earned 300 total points
ID: 2631010
You psevdocode may be as:
#include "SCNTST.h"

void main()
  //1 variables
  char szIn[100], szBar[13];
  int len, bEnd = 0;
  //init scaner
  //loop for read barcode
   {  /rread
     len = data_len (szIn)
     if (len == 0)
       bEnd = 1;//exist
          //form barcode from input
        decode_track1(szIn, szBar);
        decode_track2(szIn, szBar);
         //make something with barcode
  //Close Scaner

Expert Comment

ID: 2634559
You also need to tell the compiler where the library files are located on your drive.

The header file takes care of the compile step so your program can compile your function calls.

For the link step: you need to supply information to the linker so the library that corresponds to the header can be drawn into your executable program. The IDE that you are using will have an option screen that allows you to specify what library files to include and where they can be found. If you don't do this you will get linker errors along the lines of "Unresolved symbol" or "undefined function" or something like that.

Bill Nicholson

Author Comment

ID: 2644850
Big  Thanks   to everyone....Im  going  to accept  Alex's   answer   and  post  2  twenty  point  questions   for  captainkirk  and homer99  in  the  C  area.....again,  thanks   everyone


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question