What is happening here PLZ help me

This is a discussion on What is happening here PLZ help me within the C Programming forums, part of the General Programming Boards category; Hi all, this is very simple program but I am not getting why it is behaving like this. The second ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    10

    What is happening here PLZ help me

    Hi all,
    this is very simple program but I am not getting why it is behaving like this. The second loop is not working as I expected whats wrong in that.

    Code:
     
    
    int main()
     {
         int i,j=5;
         Xuint8  data[i];   
         Xuint32 * const customLogicPtr = (Xuint32 *)0x84018000;//bram base 
       
         print("Enter the desired number\r\n");
       
       for(i=0;i<5;i++)
       {
           data[i] =  XUartLite_RecvByte(0x84000000); 
           *(customLogicPtr+i) = data[i];
         
           xil_printf("%c,%x\r\r\n",*(customLogicPtr+i),customLogicPtr+i);
         
       }
    
        print (" This is the temporary register...\r\n");
    
        while (j)
        {
            j--;
            xil_printf("%c,%x\r\r\n",*(customLogicPtr+j),customLogicPtr+j);
        }
    
           return 0;       
     }
    This program's expected o/p is

    Enter the desired number
    1,84018000
    2,84018004
    3,84018008
    4,8401800C
    5,84018010

    This is the temporary register...
    5,84018010
    4,8401800C
    3,84018008
    2,84018004
    1,84018000


    But I am getting
    Enter the desired number
    1,84018000
    2,84018004
    3,84018008
    4,8401800C
    5,84018010

    This is the temporary register...
    1,84018010 /* why it printing value 1 at this address
    4,8401800C
    5,84018008 /* here aswell*/
    2,84018004
    1,84018000


    Thanks in advance
    Last edited by jayee_spicyguy; 11-15-2008 at 05:23 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > Xuint8 data[i];
    Unless you're using a C99 compiler, this is illegal.
    In any event, i is uninitialised, so who knows how many entries you have.

    Try
    Xuint8 data[5];
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 08:54 AM
  3. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  4. plz help me fix this problem
    By Joe100 in forum C++ Programming
    Replies: 8
    Last Post: 07-13-2003, 01:25 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM

Tags for this Thread


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