summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/regularexpressions/regex1.c
diff options
context:
space:
mode:
authortylov <[email protected]>2023-07-20 15:09:10 +0200
committertylov <[email protected]>2023-07-20 15:12:29 +0200
commit900295256d825fc323149cd223c49787f32a3696 (patch)
tree6c79cf4209e3975bb6865e2940b9cb56ea469c73 /misc/examples/regularexpressions/regex1.c
parent224a04f7fa7549ed94d2a1415eb25829e39a7cca (diff)
downloadSTC-modified-900295256d825fc323149cd223c49787f32a3696.tar.gz
STC-modified-900295256d825fc323149cd223c49787f32a3696.zip
Moved examples to sub-directories. Added cotask1.c cotask2.c examples.
Diffstat (limited to 'misc/examples/regularexpressions/regex1.c')
-rw-r--r--misc/examples/regularexpressions/regex1.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/misc/examples/regularexpressions/regex1.c b/misc/examples/regularexpressions/regex1.c
new file mode 100644
index 00000000..d8032358
--- /dev/null
+++ b/misc/examples/regularexpressions/regex1.c
@@ -0,0 +1,32 @@
+#define i_import
+#include <stc/cregex.h>
+
+int main(int argc, char* argv[])
+{
+ if (argc <= 1) {
+ printf("Usage: regex1 -i\n");
+ return 0;
+ }
+ cstr input = {0};
+ cregex float_expr = {0};
+
+ int res = cregex_compile(&float_expr, "^[+-]?[0-9]+((\\.[0-9]*)?|\\.[0-9]+)$");
+ // Until "q" is given, ask for another number
+ if (res > 0) while (true)
+ {
+ printf("Enter a double precision number (q for quit): ");
+ cstr_getline(&input, stdin);
+
+ // Exit when the user inputs q
+ if (cstr_equals(&input, "q"))
+ break;
+
+ if (cregex_is_match(&float_expr, cstr_str(&input)))
+ printf("Input is a float\n");
+ else
+ printf("Invalid input : Not a float\n");
+ }
+
+ cstr_drop(&input);
+ cregex_drop(&float_expr);
+}