Hi to all!. I have wrote a program which converts character numeric value into integer numeric value by using function atoi(string).
For example if i write 45 then it gives output :"after conversion from ascii to integer, value is 45." or if i write 4521 it gives output:"after conversion from ascii to integer value is 4521".My program is runnig perfectly, but there is a problem that when i give space in my interger e.g 45 21, then program displays 45 only and not 21. so what is the solution for this and also tell me that which header file should be included for declaration of string data type? My code for this program is as follows:
#include<iostream.h>
#include<stdlib.h>
main()
{
char x[10];
int y;
char opt;
do
{
cout<<"Enter your string"<<"\t";
cin>>x;
if(atoi(x)==0) // this function converts a character numeric value into interger numerical value
{
cout<<"you can only enter numeric values"<<endl;
}
else {
y=atoi(x);
cout<< "after conversion from ascii to integer , value is" <<y<<endl<<endl;
}
cout<<"do you want to continue? Press Y for Yes and N for No";
cin>>opt;
}
while(opt=='y'||opt=='y');
system("pause");
}