Use code tags to post code here. That preserves your code's formatting and keeps it readable.
Code:
char *convert(char *a)
{
char *array;
int i;
array=(char *)malloc(5*sizeof(char));
for (i=0;i<5;i++);
{
array[i]=a[5-i-1];
}
array[5]='\0';
return array;
}
Analyze array:
array[0] = 't'
array[1] = 's'
array[2] = 'e'
array[3] = 't'
array[4] = '\0'
array[5] is outside the bounds of the 5-element array and so "does not exist", but in reality by writing to this location you are clobbering (overwriting) whatever other data or function control value is stored there. The Thing and The Hulk can clobber, but you must not. Therefore,
array[5]='\0'; is just plain wrong and must be corrected. But that's not the problem you wrote to us about.
This statement,
array[i]=a[5-i-1];
is clumsy and stylistically would be better rendered as
array[i]=a[4-i];
Actually, that a index would in a general solution be [strlen(a)=i]; in this case strlen(a) would be 4. The for-loop should also iterate for strlen(a) -- personally, I would have assigned that function's return value to a variable for reuse.
But that's not the problem that you wrote to us about.
Look at that for-loop. I tried to bold the semicolon at the end, but you still might not see it. What you are telling the compiler is that there is block of code attached to this for-statement, so it loops 5 times doing notion except to iterate the value of i, then, since i == 5, it clobbers whatever is there with whatever comes right before the array a (ie, what's at a[-1]) and moves on. As a result, the array you return is filled with garbage, since you've never actually written to it.
Getting rid of that semicolon should clear up the problem you wrote to us about, but you have some other problems to clean up as well.