HP SunSoft Pascal 4.0 User Manual

Page 131

Advertising
background image

The C–Pascal Interface

107

6

Consider this example:

The Pascal routine,

DayWeather.p

type

TDayWeather = record

TDay: array [0..8] of char;

TWeather: array [0..20] of char;

end;

TDayWeatherArray = array [0..1] of TDayWeather;

procedure DayWeather(var W: TDayWeatherArray;

var WeatherSize: integer);

begin

W[1].TDay := 'Sunday' + chr(0);

W[1].TWeather := 'Sunny' + chr(0);

WeatherSize := 5;

end; { StruChr }

The C main program,

DayWeatherMain.c

#include <stdio.h>

#include <string.h>

struct TDayRec {

char TDay[9];

char TWeather[21];

};

extern void DayWeather(struct TDayRec [], int *);

int main(void)

{

char s25[25];

char t25[25];

struct TDayRec dr[2];

int nbytes = 0;

DayWeather(dr, &nbytes);

strncpy(s25, dr[1].TDay, 6);

printf(" day = '%s' \n", s25);

strncpy(t25, dr[1].TWeather, nbytes);

printf(" weather = '%s' \n", t25);

}

Advertising