When I did my previous program, then only I wrote my own itoa function (may have limitations) but am putting here for easy traversing. When I had a consraint to not to use any library function, then only this program came out..!
//implementation of itoa - a is the given number
my_itoa ()
{
char ptr[10];
int i=0, temp;
temp = a;
for(i=0; temp!=0 ; i++)
{
ptr[i] = temp%10 + 48;
temp = temp / 10;
}
ptr[i]='\0';
}
//reversing a string
reverse_str(char *ptr)
{
int i, j, k;
for(i=0, j=strlen(ptr)-1; i
{
k = ptr[i];
ptr[i] = ptr[j];
ptr[j]=k;
}
}
Happy programming...
No comments:
Post a Comment