Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tcc compiles c code and returns an array
#1
Hi,

The following c code defines a function tok2, which can use unicode characters as delimiters. How do I return an array? How to compile and execute in memory?

Thanks in advance for any suggestions and help
david

Macro Macro23
Code:
Copy      Help
def _DLL_tok "$desktop$\tok2.dll"
UnloadDll(_DLL_tok)

__Tcc x.Compile("" _DLL_tok 2)

dll- _DLL_tok $tok2 $s $se

_s="A┋B┋C┋D"
out tok2(_s "┋")

UnloadDll(_DLL_tok)

#ret
#include <stdio.h>
#include <string.h>

void split(char *src,const char *separator,char **dest,int *num) {
,char *pNext;
,int count = 0;
,if (src == NULL || strlen(src) == 0)
,,return;
,if (separator == NULL || strlen(separator) == 0)
,,return;
,char *strtok(char *str, const char *delim);
,pNext = strtok(src,separator);
,while(pNext != NULL) {
,,*dest++ = pNext;
,,++count;
,,pNext = strtok(NULL,separator);
,}
,*num = count;
}

__declspec(dllexport) char* tok2(const char* s,char *separator)
{
,char str[100];
,char *p[10]={0};
,int num=0,i;
,split(s,separator,p,&num);
,for(i = 0;i < num; i ++) {
,,printf("%s\n",p[i]);
,}
,return p[1];
,//return 0;
}


Messages In This Thread
Tcc compiles c code and returns an array - by Davider - 03-15-2023, 10:32 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)