Log in

View Full Version : Another programming problem for you Turiel =)


tedde
29-07-2007, 10:10 PM
Or someone else that maybe can do it.

Ok, mission is to print a nicely formatted ASCII table to the console.
Restrictions: must start with 32 and end with 255. Must be divided into columns to make it easy to read.

i've managed to come up with:

#include <iostream>
#include <iomanip>
using namespace std;

int counter = 32;

int main()
{
while(counter <= 63)
{
for(int i=0; i <= 6; i++)
{
cout.width(10);
cout.flags ( ios::right);
cout << (counter+(32*i)) << setw(3) << (unsigned char)((counter+(32*i))) << setw(3);
}
cout << endl;
counter++;
}
return 0;
}

But that doesn't generate any of the characters passed number 127 when it comes to the extended ASCII table.

Last try was something like this:

#include <iostream>
#include <iomanip>
using namespace std;

int i = -127;
int cp = 0;

int main()
{

for(int x=32; x < 64;x++)
{

cout.flags(ios::right);
cout << x << " " << char(x) << " ";
cout << x+32 << " " << char(x+32) << " ";
cout << x+64 << " " << char(x+64) << " ";
cout << x+96 << " " << char(i) << " ";
cout << x+128 << " " << char((i+32)) << " ";
cout << x+160 << " " << char((i+64)) << " " << endl;
i++;

}
return 0;
}

But that doesn't work either (+its one column too few in this one so it stops before 255)

How do I get the code to be in little windows of its own to keep the formatting?

Fithvael
29-07-2007, 10:31 PM
Turiel can you write my dissertation for me? Thanks.

Kabhanda
29-07-2007, 11:05 PM
What happened to our sex for homework scheme? :(

Kenny
30-07-2007, 06:09 AM
Chocolate Rain? :(

Flawless
31-07-2007, 01:16 AM
Turiel can you write my dissertation for me? Thanks.

Might as well get help from someone you only know over the internet rather than someone in real life who can make you look like an idiot.

tin
31-07-2007, 05:30 PM
How do I get the code to be in little windows of its own to keep the formatting?

you need to use [ code ] and [ /code ] to achieve that. And it will look like this


-Tin


edit: nice scrollbar ^^

Kinshara
31-07-2007, 05:49 PM
format strings ftw...

though if you're only allowed to use cout I guess that doesn't help.

(I'm thinking printf and friends, from the C library)

Edit: ah, referring to forum stuff rather than code. meh.

Ajial
31-07-2007, 06:02 PM
you need to use [ code ] and [ /code ] to achieve that. And it will look like this


-Tin


edit: nice scrollbar ^^

YOu are soo clever little kitteh.. *hands over some catnip*

Decebalus
01-08-2007, 06:15 AM
not sure if i understood exactly what you need but this small program compiled with BCC 3.1 on an XP system lists the chars from 32 to 254 in rows of 64...


#include <iostream.h>
#include <stdlib.h>
#include <conio.h>


unsigned char c = 32;
div_t x;

void main ()
{
clrscr();
cout << " "; // 32 spaces
while ( c < 255 )
{
cout << c;
x = div(c, 64);
if ( !x.rem ) cout << endl;
c++;
};
}


this is the output (which for some reason doesn't looks that good on the forum):

!"#$%&'()*+,-./0123456789:;<=>?@
ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
*