• Source
    1. #include <stdio.h>
    2.  
    3. void expand(char s1[], char s2[]);
    4. int getline(char s[], int lim);
    5.  
    6. int main(void) {
    7.  
    8. char s1[1000];
    9. char s2[1000];
    10.  
    11. getline(s1, 1000);
    12.  
    13. expand(s1, s2);
    14.  
    15. printf("%s", s2);
    16.  
    17. return 0;
    18. }
    19.  
    20. void expand(char s1[], char s2[])
    21. {
    22. int j = 1; //index for s2
    23. int c; // for saving starting point
    24.  
    25. s2[0] = s1[0]; //for preventing errors from 'i-1'
    26.  
    27. for(int i=1; i <= strlen(s1); i++)
    28. {
    29. if(s1[i] == '-')
    30. {
    31. if((isalpha(s1[i-1]) && isalpha(s1[i+1])) || (isdigit(s1[i-1]) && isdigit(s1[i+1])))
    32. {
    33. c = s1[i-1] + 1;
    34. while(c < s1[i+1])
    35. {
    36. s2[j++] = c++;
    37. }
    38. }
    39.  
    40. }
    41. else
    42. {
    43. s2[j++] = s1[i];
    44. }
    45. }
    46. }
    47. int getline(char s[], int lim) //getline and return length except '\0'
    48. {
    49. int c, i;
    50. for(i=0; i <= lim -1 && (c=getchar()) != EOF && c!= '\n'; i++)
    51. {
    52. s[i] = c;
    53. }
    54. if(c=='\n')
    55. {
    56. s[i] = c;
    57. i++;
    58. }
    59. s[i] = '\0';
    60. return i;
    61. }