You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Test_C/3.3.txt

40 lines
881 B

#include <stdio.h>
#include <ctype.h>
#define MAXLEN 30
void expand(char s1[], char s2[]);
int main()
{
char in[MAXLEN] = "-A-Z1-9\0";
char out[MAXLEN];
printf("s1 = %s\n", in);
expand(in, out);
printf("s2 = %s\n", out);
return 0;
}
void expand(char s1[], char s2[])
{
int i, j;
char t;
for (i = 0, j = 0; s1[i] != '\0'; i++)
{
if ( s1[i] == '-' )
{
if ( (isdigit(s1[i-1]) && isdigit(s1[i+1]) && (s1[i-1]<s1[i+1])) ||
(islower(s1[i-1]) && islower(s1[i+1]) && (s1[i-1]<s1[i+1])) ||
(isupper(s1[i-1]) && isupper(s1[i+1]) && (s1[i-1]<s1[i+1])) )
for (t = (char)(s1[i-1]+1); t < s1[i+1]; t++)
s2[j++] = t;
else
s2[j++] = s1[i];
}
else
s2[j++] = s1[i];
}
s2[j] = '\0';
}