DLL Programmer's Guide for TNS/R Systems
Sample Sessions and Usage Notes
DLL Programmer’s Guide for TNS/R Systems—522203-002
6-2
Sample Session One
Sample Session One
This sample session shows the use of a main program mainstrc and second program,
a library called mystrngc. Both will be compiled using nmc, then loaded using nld.
mystrngc will be loaded as an SRL. This will show you the default situation.
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 ) {