DLL Programmer's Guide for TNS/E Systems

Example Code
DLL Programmer’s Guide for TNS/E Systems—527252-006
6-2
Example One
Example One
This example shows the use of a main program, mainstrc, and a library called
mystrngc. Both will be compiled using ccomp, then linked using eld. mystrngc will be
loaded as a DLL.
Display the Source Code
Here is the code for the main program, mainstrc
#include <stdio.h> nolist
#include <stdlib.h> nolist
#include <string.h> nolist
int StrRev (char *s, char *r); /* declaration of external procedure */
char s[100];
/***********************************************************
| main: given a list of strings, print out them reversed
| argv[1]...argv[argc-1] point to strings
|
| if no string passed, put out usage message and quit.
| for each string
| reverse it
| display it
|
\***********************************************************/
int main(int argc, char *argv[]) {
char **ppStr;
int strLeft;
int outcome;
if (argc < 2) /* no args passed */
{
printf("Usage: run rev <str1> [<str2>] ....\n \
\twhere <str> is a string to reverse\n \
\texample: run rev abc zyxw\n");
exit(1);
}
for (strLeft= argc-1, ppStr=argv+1;
strLeft;
ppStr++, strLeft-- ) {
strcpy(s, *ppStr);
outcome = StrRev( s, s );
(outcome == 0) ? printf( "Reverse(%s) = (%s)\n", *ppStr, s ) :
printf( "error in reversing the string\n");
} /* for */
printf("Hit enter to finish\n");
getchar( );
} /* of proc main */
Here is the source code for the library, mystrngc
#include <string.h> nolist
#include <stdlib.h> nolist
int StrRev (char *s, char *r ) {