fork download
  1.  
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. char s2[1000];
  5. void expand(char s1[],char s2[])
  6. {
  7. int i=0,k=0;
  8. char j;
  9. for(i=0;s1[i]!='\0';i++)
  10. {
  11. if(s1[i]=='-' && i && s1[i+1]!='\0' )
  12. {
  13.  
  14. if(s1[i-1]+1<=s1[i+1])
  15. for(j=s1[i-1]+1;j<=s1[i+1];j++) /*straight*/
  16. s2[k++]=j;
  17. else
  18. for(j=s1[i-1]-1;j>=s1[i+1];j--) /*reverse*/
  19. s2[k++]=j;
  20. i++;
  21. }
  22. else
  23. s2[k++]=s1[i];
  24. }
  25. s2[k]='\0';
  26. }
  27. int main(void) {
  28. char *s[] = { "a-z-", "z-a-", "-1-6-",
  29. "a-ee-a", "a-R-L", "1-9-1",
  30. "5-5", NULL };
  31.  
  32. int i = 0;
  33.  
  34. while ( s[i] ) {
  35.  
  36. /* Expand and print the next string in our array s[] */
  37.  
  38. expand(s2, s[i]);
  39. printf("Unexpanded: %s\n", s[i]);
  40. printf("Expanded : %s\n", s2);
  41. ++i;
  42. }
  43.  
  44. return 0;
  45. }
  46.  
Runtime error #stdin #stdout 0.01s 1716KB
stdin
Standard input is empty
stdout
Standard output is empty