shomikc
Member level 4
I started teaching Atmel AVR microcontroller this semester.
I need to reverse an array, the first element of array being swapped with last and second element being swapped with second last and so on.
I am getting a recipe for target *.elf failed error.
Please help.
I need to reverse an array, the first element of array being swapped with last and second element being swapped with second last and so on.
I am getting a recipe for target *.elf failed error.
Please help.
Code:
#include <avr/io.h>
//void swap (int *px, int *py);
void swap (char *px, char *py)
{
char temp;
temp = *px;
*px = *py;
*py = temp;
}
void reversal (char a[ ], char n)
{
char i, j, k;
j = n%2;
// n is the number of elements in the array
if (j == 1)
k = n + 1;
for (i = 0; i < (k)/2 ; i++)
{
swap (&a[i], &a[n - i - 1]);
}
/*for (i = 0; i < n ; i++)
{
printf("%d \n",a[i] );
}*/
}
int main(void)
{
/* Replace with your application code */
char n = 5;
char a[5] = {1, 2, 3, 4, 5};
//reversal(a, n);
}