sumankhanal

nativecall-c-3

Jun 18th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. /*test.c */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. int count(char *String)
  7. {
  8.      return strlen(String);
  9. }
  10.  
  11. int count_char(char *String, char toSearch)
  12. {
  13.     int i, count;
  14.  
  15.     count = 0;
  16.     i=0;
  17.     while(String[i] != '\0')
  18.     {
  19.         /*
  20.          * If character is found in string then
  21.          * increment count variable
  22.          */
  23.         if(String[i] == toSearch)
  24.         {
  25.             count++;
  26.         }
  27.  
  28.         i++;
  29.     }
  30.  
  31.     return count;
  32. }
  33.  
  34.  
  35. # Raku code
  36.  
  37. use NativeCall;
  38. sub count(Str) returns int32 is native('libtest') { * };
  39. sub count_char(Str, Str) returns int32 is native('libtest') { * };
  40. say count("nativecall");
  41. say count_char("nativecall", "a")
  42.  
  43.  
  44. # While count works , count_char doesn't. How can I make it work?
  45. # I am in windows 10, and the dynamic library generated is libtest.dll
Add Comment
Please, Sign In to add comment