#include<iostream.h>
#include<string.h>
int main()
{
int x;
cout<<endl<<"enter x:";
cin>>x;
int temp=x;
int count=0;
while(temp!=0)
{
count++;
temp=temp/10;
}
char *p=new char[count+1];
for(int i=0;i<count;i++)
{
*(p+i)='\0';
}
for(i=count-1;i>=0&&x!=0;i--)
{
*(p+i)=x%10;
x=x/10;
}
*(p+count)='\0';
cout<<endl<<"converted string : ";
for(i=0;i<count;i++)
cout<<(int)*(p+i); // int type cast used , if not used then integers are not printed in cout
//is there an alternative method ?
return 0;
}
amitahlawat20 0 Light Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Narue 5,707 Bad Cop Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.