Thread: What's wrong?

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    75

    Question What's wrong?

    Compiler says:
    -two or more data types in declaration of `presentar'
    -conflicting types for 'presentar'
    -previous declaration of 'presentar'

    What's wrong in my program??

    Code:
    #include <stdio.h>
    
    union byte{
      unsigned char byte;
      struct{
        unsigned char b0:1;
        unsigned char b1:1;
        unsigned char b2:1;
        unsigned char b3:1;
        unsigned char b4:1;
        unsigned char b5:1;
        unsigned char b6:1;
        unsigned char b7:1;
      }bits;
    }
    
    void presentar(unsigned char c);
    unsigned char reflejarbyte(union byte b);
    
    main(void)
    {
      union byte b;
      
      printf("Introduzca un caracter: ");
      b.byte=getchar();
      presentar(b.byte);
      
      b.byte=reflejarbyte(b);
      printf("Caracter reflejado: %c\n",b.byte);
      presentar(b.byte);
    }
    
    void presentar(unsigned char c)
    {
      int i=0;
      
      printf("El valor ASCII de %c es %Xh; en binario:",c,c);
      for(i=7;i>=0;i--)
        printf("%d",(c&(1<<i))?1:0);
      printf("\n");
    }
    
    unsigned char reflejarbyte(union byte b)
    {
      union byte c;
      
      c.bits.b0=b.bits.b7;
      c.bits.b1=b.bits.b6;
      c.bits.b2=b.bits.b5;
      c.bits.b3=b.bits.b4;
      c.bits.b4=b.bits.b3;
      c.bits.b5=b.bits.b2;
      c.bits.b6=b.bits.b1;
      c.bits.b7=b.bits.b0;
      
      return (c.byte);
    }
    ---Programming is like roaming, you never know where you'll end at------

    If 'here' is pronounced as 'hear', why 'there' isnt pronounced as 'dear'??

    [email protected]

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    union byte{
      unsigned char byte;
      struct{
        unsigned char b0:1;
        unsigned char b1:1;
        unsigned char b2:1;
        unsigned char b3:1;
        unsigned char b4:1;
        unsigned char b5:1;
        unsigned char b6:1;
        unsigned char b7:1;
      }bits;
    }; /* Don't forget the semicolon */
    -Prelude
    My best code is written with the delete key.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You can reverse the bits using a loop too...
    Code:
    #define O unsigned char
    O x0(O x00){O x01=0x00;int x;for(x=
    0x00;x<sizeof(O)<<0x03;x+=0x01){if
    (x00&0x01<<x)x01|=(0x01<<(((sizeof
    (O)<<0x03)-0x01)-x));}return x01;}


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM