]> piware.de Git - learn-rust.git/blobdiff - call-rust-from-c/src/main.c
Call Rust function from C: Complex cases
[learn-rust.git] / call-rust-from-c / src / main.c
index b514433ce6fc8d680ffa67b9090ee60ed6afdb9a..a8f7dbcc4816e951bc91ce10b6e4ccd19e0290e2 100644 (file)
@@ -3,6 +3,20 @@
 
 int main()
 {
+    const char *hello = "hello";
+    const char *haystack = "Hello\nworld\ncan you tell?";
+
     printf("The answer: %i\n", answer());
+    printf("Length of '%s': %u\n", hello, r_strlen(hello));
+
+    const unsigned char **strs = r_strlist();
+    for (const unsigned char **s = strs; *s; s++)
+        printf("returned string array element: %s\n", *s);
+    free (strs);
+
+    const char **matches = r_grep("ell", "Hello\nworld\ncan you tell?");
+    for (const char **m = matches; *m; m++)
+        printf("matched line: %s\n", *m);
+    free (matches);
     return 0;
 }