This is my program for RunLength Decoding. But is is giving output as garbage values. The output in the char *decode_rle(char *a,int length) method is correct, but when it is returned to the main function it is wrong. 
#include<stdio.h>
#include<string.h>
char *decode_rle(char *a,int length)
{
    char op[50];
    int i,j,k=0,count=0;
    for(i=0;i<length;i++)
    {
        if( a[i]=='a' || a[i]=='b' || a[i]=='c' || a[i]=='d' || a[i]=='e' || a[i]=='f' || a[i]=='g')
        {
            count = a[i+1] - '0';
            for(j=0;j<count;j++)
            {
                op[k]=a[i];
                k++;
            }
        }
    }
    op[k] = '\0';
printf("\n the decoded string is %s\n",op);
    return op;
}
int main()
{
    int i=0,j,length,count;
    char a[20],*output;
    printf("\n Enter a string ");
    gets(a);
    printf("\n The string you entered is %s",a);
    length = strlen(a);
    printf("\n length is %d\n",length);
    output = decode_rle(a,length);
    i=0;
    while(output[i]!='\0')
    {
        printf("%c",output[i]);
        i++;
   }
    getch();
    return 0;
}
 
     
     
    