Solved

how to call functions

Posted on 2000-03-17
10
186 Views
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  

DaveMon
0
Comment
Question by:DaveMon
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 2

Expert Comment

by:homer99
ID: 2628659
DaveMon:

The first thing that you need to do is to include the header file at the top of your code:
#include<header.h>

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:

#include<header.h>

main()
{
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.







0
 
LVL 2

Expert Comment

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

Expert Comment

by:AlexVirochovsky
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

0
 
LVL 2

Author Comment

by:DaveMon
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

DaveMon
0
 
LVL 4

Expert Comment

by:captainkirk
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);
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 3

Expert Comment

by:3rsrichard
ID: 2629489
You tell your program what procedures you are going to use by putting
#include<thenameoftheheaderfile.h>
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.
0
 
LVL 2

Expert Comment

by:anupvijay
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.
Anup
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 100 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
  InitScaner();
  //loop for read barcode
  while(!bEnd)
   {  /rread
     ReadBarCode(szIn);
     len = data_len (szIn)
     if (len == 0)
       bEnd = 1;//exist
     else
       {
          //form barcode from input
        decode_track1(szIn, szBar);
        decode_track2(szIn, szBar);
         //make something with barcode
       ....
       }
   }
  //Close Scaner
  CloseScaner();
}
0
 

Expert Comment

by:nicomp
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
0
 
LVL 2

Author Comment

by:DaveMon
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


DaveMon
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now