コード例 #1
0
void expand(char s1[],char s2[])
{
	int i,j;
	s2[0]=s1[0];
	for (i=j=1;s1[i]!='\0';i++)
	{
		switch (s1[i])
		{
			case '-':
				if (validrange(s1[i-1],s1[i+1]))
				{
					while (s2[j-1]<s1[i+1])
					{
						s2[j]=s2[j-1]+1;
						j++;
					}
					i++;
				}
				else 
					s2[j++]=s1[i];break;
			default:
				s2[j++]=s1[i];break;
		}
		
		s2[j]='\0';
	}
}
コード例 #2
0
/* expand:  expands shorthand notations in the string s1 into the
            equivalent complete list in s2 */
void expand(char s1[], char s2[])
{
    int i, j;
    char tmp;
    int dash;

    dash = 0;
    for (i = j = 0; s1[i] != '\0'; ++i) {
        if (s1[i] == '-') {
            if (i == 0 || s1[i+1] == '\0') {
                /* '-' is leading or trailing, so just copy it. */
                s2[j++] = s1[i];
            } else {
                /* check if this is a valid range. */
                if (validrange(s1[i-1], s1[i+1])) {
                    while (s2[j-1] < s1[i+1]) {
                        s2[j] = s2[j-1] + 1;
                        j++;
                    }
                    /* skip next character we already printed it. */
                    ++i;
                } else {
                    s2[j++] = s1[i];
                }
            }
        } else {
            s2[j++] = s1[i];
        }
    }
    /* End the string with a NUL byte */
    s2[j] = '\0';
}