c++ - Variable becomes empty after entering for-loop -


        ma=arraytolist(a);         mb=arraytolist(b);         mc=arraytolist(c);         md=arraytolist(d);         if(mb==null) cout<<"b empty"; // it's ok here         for(;ma!=null;ma=ma->next){             if(mb==null) cout<<"b empty"; // mb==null, same mc             bool f = true;             for(;f && mb!=null;mb=mb->next)                 if(ma->elem==mb->elem) f = false;             for(;f && mc!=null;mc=mc->next)                 if(ma->elem==mc->elem) f = false;             if(f){                 me=new mult;                 me->elem=ma->elem;                 me->next=me;                 me=me;             }         } 

the problem mb , mc become empty right after string

        for(;ma!=null;ma=ma->next){ 

any suggestions?

upd: mb , mc become empty before first iteration (before iteration body), not after finishes. how mb looks like

typedef struct st {    char elem;    struct st* next; }mult; 

this arraytolist does:

mult* arraytolist(char *arr) {     mult *head=null, *phead;     (int = 0; arr[i]; i++)     {         phead = new mult;         phead->elem = arr[i];         phead->next = head;         head = phead;     }     return head; } 

how see it:

typedef struct st {    char elem;    struct st* next; }mult;  int main(){ //initialization of mult *ma, *mb, *mc, *md; //at point 4 variables not empty , can shown correctly for(;ma!=null;ma=ma->next){     //right after point mb , mc somehow become empty, ma still ok     //some stuff } } 

hope more clear now


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -