From 33f3e3f2bdd7e4eaf89e9708505d3c0d27fc23f7 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 4 Jun 2022 12:50:05 +0530 Subject: rewrite deleted 3.3.c (whole reason to make this git repo) --- 3.3.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 3.3.c diff --git a/3.3.c b/3.3.c new file mode 100644 index 0000000..e27078c --- /dev/null +++ b/3.3.c @@ -0,0 +1,36 @@ +#include + +#define MAXLEN 1000 + +char* expand(char coom[], char str[]); + +int +main(void) +{ + char coom[] = "sneed a-z a-b-c a-z0-9 -a-z sneed"; + char str[MAXLEN]; + + printf("%s\n%s\n", coom, expand(coom, str)); + + return 0; +} + +char* +expand(char from[], char to[]) +{ + int i, j, k; + + for (i = 0, j = 0; from[i] != '\0'; i++) { + to[j++] = from[i]; + + for (k = from[i]+1; ((from[i] >= '0' && from[i] <= '9') || (from[i] >= 'a' && from[i] <= 'z') || (from[i] >= 'A' && from[i] <= 'Z')) && from[i+1] == '-' && k < from[i+2]; k++, j++) + to[j] = k; + + if (from[i+1] == '-' && ((from[i] >= '0' && from[i] <= '9') || (from[i] >= 'a' && from[i] <= 'z') || (from[i] >= 'A' && from[i] <= 'Z'))) + i++; + } + + to[j] = '\0'; + + return to; +} -- cgit v1.2.3