I've made one C++ program using pointers and functions to return the reverse of a string. When the range char p[] in the function rev is low like 25 (less than. 145), the output is like ►↕☻ ☺♠♥, it doesn't reverse, when the range is higher than 145, it works fine in gcc, for Borland TurboC, the minimum range must be 65 otherwise the program prints strange values instead of reversing it.
#include<iostream>
#include<conio.h>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
char str[20];
int l;
char* p1;
//clrscr();
gets(str);
l=strlen(str);
char* rev(char*,int);
p1=rev(str,l);
puts(p1);
return 0;
//getch();
}
char * rev(char* a,int l1)
{
char p[25]; // HERE: higher than 146 is working
int c=0;
for(l1=l1-1;l1>=0;l1--)
{
p[c]=a[l1];
c++;
}
p[c]=NULL;
return(p);
}