Well i wish i had a teacher, im just self studying from the C book.
I did write the code for this, based on another code i found and its output looked like this - see attachment.
Anyway, this is the code i wrote...
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 1024
void expand (char dest[], char s[])
{
int x = 0, y, z = 0;
while(s[x] !='\0')
{
if((x == 0 || s[x+1] == '\0') && s[x] == '-') /* first or last char is a dash */
dest[z++] = s[x];
else if(s[x] == '-')
{
if(s[x-1] >='0' && s[x-1] <='9') /* checking left char */
{
if(s[x+1] >='0' && s[x+1] <='9') /* checking right char */
{
if(s[x-1] < s[x+1])
{
for(y = s[x-1]; y <= s[x+1]; y++)
dest[z++] = y;
}
else if(s[x-1] == s[x+1])
dest[z++] = s[x-1];
else
{
for(y = s[x-1]; y>= s[x+1]; y--)
dest[z++] = y;
}
}
else if((s[x+1]>='a' && s[x+1] <='z') || (s[x+1]>='A' && s[x+1] <='Z'))
printf("Mismatching argument to expand.\n");
else dest[z++] = s[x];
}
else if(s[x-1] >='a' && s[x-1] <='z')
{
if(s[x+1] >='a' && s[x+1] <='z')
{
if(s[x-1] < s[x+1])
{
for(y = s[x-1]; y<=s[x+1]; y++)
dest[z++] = y;
}
else if(s[x-1] == s[x+1])
dest[z++] = s[x-1];
else
{
for(y = s[x-1]; y>=s[x+1]; y--)
dest[z++] = y;
}
}
else if((s[x+1] >='0' && s[x+1]<='9') || (s[x+1]>='A' && s[x+1] <='Z'))
printf("Mismatching argument to expand.\n");
else dest[z++] = s[x];
}
else if(s[x-1] >='A' && s[x-1] <='Z')
{
if(s[x+1] >='A' && s[x+1] <='Z')
{
if(s[x-1] < s[x+1])
{
for(y = s[x-1]; y<=s[x+1]; y++)
dest[z++] = y;
}
else if(s[x-1] == s[x+1])
dest[z++] = s[x-1];
else
{
for(y = s[x-1]; y>=s[x+1]; y--)
dest[z++] = y;
}
}
else if((s[x+1] >='0' && s[x+1] <='9') || (s[x+1] >='a' && s[x+1] <='z'))
printf("Mismatching argument to expand.\n");
else dest[z++] = s[x];
}
else dest[z++] = s[x]; /* a leading -, just put it in the string */
}
else if(s[x+1] == '-') /* check if leading dash */
{
if((s[x] >='0' && s[x] <='9') || (s[x] >='a' && s[x] <='z') || (s[x] >='A' && s[x] <='Z'))
;
else dest[z++] = s[x];
}
else if(s[x-1] != '-' && s[x+1] !='-')
dest[z++] = s[x];
x++;
}
dest[z] = '\0';
}
int main(int argc, char *argv[])
{
char s[MAX_SIZE] = "-r-a--";
char destination[MAX_SIZE];
expand(destination, s);
printf("%s", destination);
putchar('\n');
system("PAUSE");
return 0;
}