help in XORring

This is a discussion on help in XORring within the C Programming forums, part of the General Programming Boards category; I am trying to solve this code but its make me confuse all the time .can any one help me ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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,185
    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
    21,941
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,941
    You don't necessarily have to use pointers; you are probably just not writing the code correctly. What exactly are you trying to do?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,941
    Post your code.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21