RosettaCodeData/Task/Call-a-foreign-language-function/FutureBasic/call-a-foreign-language-function.basic

21 lines
476 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
include "NSLog.incl"
BeginCDeclaration
char *strdup(const char *src);
EndC
BeginCFunction
char *strdup(const char *src) {
char *dst = malloc(strlen (src) + 1); // Space for length plus null
if (dst == NULL) return NULL; // No memory
strcpy(dst, src); // Copy the characters
return dst; // Return the new string
}
EndC
BeginCCode
NSLog( @"%s", strdup( "Hello, World!" ) );
EndC
HandleEvents