25 lines
1.0 KiB
Plaintext
25 lines
1.0 KiB
Plaintext
{{clarified-review}}
|
|
This task is inverse to the task [[Call foreign language function]]. Consider the following [[C]] program:
|
|
<lang c>#include <stdio.h>
|
|
|
|
extern int Query (char * Data, size_t * Length);
|
|
|
|
int main (int argc, char * argv [])
|
|
{
|
|
char Buffer [1024];
|
|
size_t Size = sizeof (Buffer);
|
|
|
|
if (0 == Query (Buffer, &Size))
|
|
{
|
|
printf ("failed to call Query\n");
|
|
}
|
|
else
|
|
{
|
|
char * Ptr = Buffer;
|
|
while (Size-- > 0) putchar (*Ptr++);
|
|
putchar ('\n');
|
|
}
|
|
}</lang>
|
|
|
|
Implement the missing <code>Query</code> function in your language, and let this C program call it. The function should place the string ''<tt style="margin:0 0.5em">Here am I</tt>'' into the buffer which is passed to it as the parameter <code>Data</code>. The buffer size in bytes is passed as the parameter <code>Length</code>. When there is no room in the buffer, <code>Query</code> shall return 0. Otherwise it overwrites the beginning of <code>Buffer</code>, sets the number of overwritten bytes into <code>Length</code> and returns 1.
|