6

The C function, StrVar.c

#include <string.h>

struct TVarLenStr {

int nbytes; char a[26];

};

void StrVar(char *s10, char *s80, struct TVarLenStr *vls)

{

static char ax[11] = "abcdefghij";

static char sx[81] = "abcdefghijklmnopqrstuvwxyz"; static char vx[6] = "varstr";

strncpy(s10, ax, 11); strncpy(s80, sx, 80); strncpy(vls->a, vx, 6); vls->nbytes = 6;

}

The Pascal main program, StrVarMain.p

program StrVarMain(output); type

TVarStr = varying[26] of char;

var

a:alfa;

s:string;

v:TVarstr;

procedure StrVar(var a: alfa; var s: string; var v: TVarStr); external c;

begin

StrVar(a, s, v); writeln(a); writeln(s); writeln(v);

writeln(' length(v) = ', length(v) :2); end. { StrVarMain }

The C–Pascal Interface

119

Page 143
Image 143
HP SunSoft Pascal 4.0 manual C function, StrVar.c, Pascal main program, StrVarMain.p, C-Pascal Interface 119