-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.3_expand2.c
63 lines (50 loc) · 1.03 KB
/
3.3_expand2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* A function to expand short hand notations like a-z in string s1
* into the equivalent complete list (abcdefghi...xyz) in s2
*
* Also allow for either case and digits.
*
* This is better, more modular (atomic).
*/
#include <stdio.h>
#include <string.h>
#define MAXLINE 30
void escape(char* s1, char* s2)
{
int i, j, c;
i = j = 0;
while((c = s1[i++]) != '\0'){
if(s1[i] == '-' && s1[i+1] >= c)
{
i++;
while(c < s1[i]){
s2[j++] = c++;
}
}
else
{
s2[j++] = c;
}
}
s2[j] = '\0';
}
void my_getline(char *s)
{
int i, c = 0;
for (i = 0; i < MAXLINE && ((c = getchar()) != EOF) && c != '\n'; i++)
{
s[i] = c;
}
// if(c=='\n')
// s[i++]=c;
s[i] = '\0';
}
int main(void)
{
char s1[MAXLINE];
char s2[MAXLINE];
my_getline(s1);
escape(s1, s2);
printf("Original: %s\n\n", s1);
printf("Here's your complete sequence: %s\n", s2);
}