Created
January 11, 2016 15:02
-
-
Save krysseltillada/1677ea73e32b4bb341e7 to your computer and use it in GitHub Desktop.
ex 3-3 (the c programming language)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void expand (char s1[], char s2[]) | |
{ | |
int i = 0, n, x = 0; | |
if (s1[i] >= 'a' && s1[i + 1] == '-' && s1[i + 2] <= 'z') { | |
if (s1[i + 3] == '-' && (s1[i + 2] >= s1[i] && s1[i + 2] <= s1[i + 4]) && s1[i + 4] <= 'z') { | |
for (n = s1[i]; n <= s1[i + 4]; ++n, ++x) | |
s2[x] = n; | |
s2[x] = '\0'; | |
return; | |
} | |
else if (s1[i + 3] >= '0' && s1[i + 4] == '-' && s1[i + 5] <= '9') { | |
for (n = s1[i]; n <= s1[i + 2]; ++n, ++x) | |
s2[x] = n; | |
s2[x++] = '\n'; | |
for (n = s1[i + 3]; n <= s1[i + 5]; ++n, ++x) | |
s2[x] = n; | |
s2[x] = '\0'; | |
return; | |
} | |
for (n = s1[i]; n <= s1[i + 2]; ++n, ++x) | |
s2[x] = n; | |
s2[x] = '\0'; | |
return; | |
} | |
if (s1[i] == '-' && s1[i + 1] >= 'a' && s1[i + 2] == '-' && s1[i + 3] <= 'z') { | |
for (n = s1[i + 1]; n <= s1[i + 3]; ++n, ++x) | |
s2[x] = n; | |
s2[x] = '\0'; | |
} | |
} | |
int main () | |
{ | |
char str[100]; | |
expand("-b-t", str); | |
printf ("%s\n", str); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment