View Single Post
Old 01-22-2005, 08:03 AM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,695
redhead is on a distinguished road
You're off by one:
Code:
      for (i=0; i < a_elem; i++)   {
           printf("\nelement: ");
           scanf("%d ", &i_array[index]);
           index++;           
        }
     index=a_elem;
When exiting this loop your index is pointing at the NULL terminating your initial array.
So when you reverse:
Code:
     
     for (i=0; i< a_elem; i++)     {
           rev_array[rev_index]=i_array[index];
           index--;
           rev_index++;             
        }
Your initial value will be an int representing NULL as the first value in the reversed array. And since you're testing i against the array size, you'll miss the first value in your initial array.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote