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);
}
Содержание 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: ......