CrazyEngineers
  • Function returning string

    Vicky One

    Member

    Updated: Oct 26, 2024
    Views: 1.2K
    Can any one correct the following code and explain...
    The function decode is returning a string and i want that local string to be stored in another string in main which calls that function.
    
     
    #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    void decode(char q[]);
    int main()
    {  //p refers to orignal string and q refers to quoted string
    char a,b,c,d,e,f,g,h,i;
    char p[]="011100011";
    cout<<p;
    cout<<endl;
    a=(p[0]+p[1]-'0');
    b=((p[0]+p[1]-'0'+p[2])-'0');
    c=((p[1]+p[2]-'0'+p[3])-'0');
    d=((p[2]+p[3]-'0'+p[4])-'0');
    e=((p[3]+p[4]-'0'+p[5])-'0');
    f=((p[4]+p[5]-'0'+p[6])-'0');
    g=((p[5]+p[6]-'0'+p[7])-'0');
    h=((p[6]+p[7]-'0'+p[8])-'0');
    i=(p[7]+p[8]-'0');
    char q[9]={a,b,c,d,e,f,g,h,i};
    char sum[]=decode(q);
    cout<<sum;
    }
    return decode(char q[])
    {
    char ap,bp,cp,dp,ep,fp,gp,hp,ip;
    ap=0;
    bp=q[1]-ap;
    cp=q[2]-ap-bp;
    dp=q[3]-bp-cp;
    ep=q[4]-cp-dp;
    fp=q[5]-dp-ep;
    gp=q[6]-ep-fp;
    hp=q[7]-fp-gp;
    ip=q[8]-gp-hp;
    char string1[]={ap,bp,cp,dp,ep,fp,gp,hp,ip};
    return string1;
    }
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Home Channels Search Login Register