C++/c++
Expert: Prince M. Premnath - 4/11/2010
QuestionHi Prince M.Premnath,
I'm new in c++ and I've writen a program which can produce ascii codes.Could you write me how can I write this program that when I run it,it show me ascii codes columnar?
32 64 96 128 160 192 224
33 65 97 129 161 193 225
and so on...
I tried do this with two 'for' but it doesn't work.I cannot use
char 255!
here is program :
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout <<"*************** ASCII Table **************** "<<endl ;
cout<<endl;
for(int col=1; col<=7; col++)
{
for(int row=1; row<=32; row++)
{
for (unsigned char uch=32; uch<=254; uch++)
{
cout<<right;
cout<<setw(5)<<uch<<setw(5)<<int(uch);
}
}
}
//cout<<endl;
return 0;
}
Regards,
tina.
AnswerHai dear Tina !
char data type have some limitations it cannot go beyond 0-255 once if it reaches 255 limit further any increment will reset the value to 0 this will end up in an infinite loop,
please find the modified code below , i suggest you to go with this
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout <<"*************** ASCII Table **************** "<<endl ;
cout<<endl;
for (int uch=32; uch<=255; uch++)
{
cout<<right;
cout<<setw(5)<<uch<<setw(5)<<char(uch);
}
cin.get();
return 0;
}
Get back to me in case of queries :)
Thanks and Regards !
Prince M. Premnath