Advertisement
Guest User

Gyak

a guest
Dec 12th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. char* unpack(char *input) {
  5.     int i=0;
  6.     int j=0;
  7.     int ch;
  8.     char* output = malloc(1000*sizeof(char));
  9.     while(input[i]!=0) {
  10.         if(input[i]=='[') {
  11.             for(ch = input[i+1]; ch<=input[i+3]; ch++) {
  12.                 output[j]=ch;
  13.                 j++;
  14.             }
  15.             i=i+5;
  16.         }
  17.         else {
  18.             output[j] = input[i];
  19.             i++;
  20.             j++;
  21.         }
  22.     }
  23.     return output;
  24. }
  25.  
  26. int main() {
  27.     char input[]="hello [a-c] bello [d-k] aa";
  28.     char input2[]="Wtf???";
  29.     char* output = unpack(input2);
  30.     printf("%s\n%s\n", input2, output);
  31.     free(output);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement