The C–Pascal Interface
97
6
Fixed Arrays
For a fixed array parameter, pass the same type and size by reference, as
shown in the following example:
The C main program,
StrVarMain.c
#include <stdio.h>
#include <string.h>
struct TVarLenStr {
int nbytes;
char a[25];
};
extern void StrVar(char *, char *, struct TVarLenStr *);
int main(void)
{
struct TVarLenStr vls;
char s10[10], s80[80], s25[25];
vls.nbytes = 0;
StrVar(s10, s80, &vls);
strncpy(s25, vls.a, vls.nbytes);
printf(" s10 = '%s' \n s80 = '%s' \n s25 = '%s' \n",
s10, s80, s25);
printf(" strlen(s25) = %d \n", strlen(s25));
}
The commands to compile and
execute
StrVar.p
and
StrVarMain.c
hostname% pc -c StrVar.p
hostname% cc StrVar.o StrVarMain.c -lpc
hostname% a.out
s10='abcdefghi'
s80='abcdefghijklmnopqrtstuvwxyz'
s25='varstr'
strlen(s25)=6
Содержание SunSoft Pascal 4.0
Страница 14: ...xiv Pascal 4 0 User s Guide ...
Страница 16: ...xvi Pascal 4 0 User s Guide ...
Страница 30: ...6 Pascal 4 0 User s Guide 1 ...
Страница 160: ...136 Pascal 4 0 User s Guide 6 ...
Страница 268: ...244 Pascal 4 0 User s Guide 11 ...
Страница 320: ...296 Pascal 4 0 User s Guide B ...
Страница 331: ...Index 307 ...
Страница 333: ......