Thread: help in XORring

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    4

    help in XORring

    I am trying to solve this code but its make me confuse all the time .can any one help me to correct this program.






    Code:
    int main()
    
    {
    int a[2]={29,33};
    int *b[2];
    int i,j,*linea[2],*lineb[2],*linec[2];
    
    for (j=0;j<=1;j++)
    {
     b[j]=&a[j];
     
    printf("value of a %d\n",b[j]);
    }      
    for(i=0;i<=1;i++)
    {
    linea[i]=b[0];
    linea[i]=b[1];
    linec[i]= linea[i] ^ lineb[i];
    
    printf(" %d\n",linec[i]);
    }
    getch();
    }

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    What are you trying to do?

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    and what is wrong here?

    except your printing pointers with %d instead of %p.

    Describe your problem if you want help with how to fix it
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    4
    I am XORing 29 with 33 so my output will be 60..Thats I want acutally but i is showing error

    Code:
    Invalid Operands of types int* and int* to binary operator^
    plz help me to solve it

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The easy answer is "dereference the pointers to get the values". The real answer is "why do you have all these pointers anyway?"

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Like this, perhaps?
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        printf("%d\n", 29 ^ 33);
        return 0;
    }
    I cannot really tell what all that other code is supposed to do.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by mehakII View Post
    I am trying to solve this code but its make me confuse all the time .can any one help me to correct this program.






    Code:
    int main()
    
    {
    int a[2]={29,33};
    int *b[2];
    int i,j,*linea[2],*lineb[2],*linec[2];
    
    for (j=0;j<=1;j++)
    {
     b[j]=&a[j];
     
    printf("value of a %d\n",b[j]);
    }      
    for(i=0;i<=1;i++)
    {
    linea[i]=b[0];
    linea[i]=b[1];
    linec[i]= linea[i] ^ lineb[i];
    
    printf(" %d\n",linec[i]);
    }
    getch();
    }

    Okay, the code makes no sense, but the following bugs exist:
    1. linea[i]=b[1];
    Should be lineb
    2. linec[i]= linea[i] ^ lineb[i];
    linea[i] and lineb[i] are pointers. I think you mean:
    linec[i]= *linea[i] ^ *lineb[i];
    except that linec[i] can't be a pointer to an integer but should just be an array of integers.

    I think that would make it work. But the rest of the code suggests to me that you really have no idea what you're doing, especially with pointers/arrays. Either that, or this is some very small snippet of a huge buggy piece of code.

    My advice: read up on pointers and arrays before you code anything else.

  8. #8
    Registered User
    Join Date
    Mar 2010
    Posts
    4
    I am writing my program in NES-C language ,the problem is I have to use pointers otherwise it gives me some other errors like

    Code:
    invalid conversation from int* to int
    I want the same program with solution.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You don't necessarily have to use pointers; you are probably just not writing the code correctly. What exactly are you trying to do?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Mar 2010
    Posts
    4
    if I only use intergers then it gives me error invalid operands to binary

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Post your code.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed