Next: , Up: File Library Examples


6.8.3.1 The Powers Of Two

Over the course of our activity we have accumulated a great deal of wisdom. Now we want to record that wisdom so that generations to come may have something and do not carry on through their sorry lifes empty handed. And what better way to record wisdom than write it in a file?

We will record all the powers of two that we know of (they are but a few).

We will need a file:

file wisdom;

We will open some file, kind of like in C:

f_open(wisdom, "wisdom", OPEN_CREATE | OPEN_TRUNCATE | OPEN_WRITEONLY, 00644);

Write those powers:

f_mode(wisdom, 1);
f_byte(wisdom, '\n');
f_mode(wisdom, 2);
f_byte(wisdom, '\n');
f_mode(wisdom, 4);
f_byte(wisdom, '\n');
f_mode(wisdom, 8);
f_byte(wisdom, '\n');
f_mode(wisdom, 16);
f_byte(wisdom, '\n');
f_mode(wisdom, 32);
f_byte(wisdom, '\n');
f_mode(wisdom, 64);
f_byte(wisdom, '\n');
f_mode(wisdom, 128);
f_byte(wisdom, '\n');
f_mode(wisdom, 256);
f_byte(wisdom, '\n');
f_mode(wisdom, 512);
f_byte(wisdom, '\n');
f_mode(wisdom, 1024);
f_byte(wisdom, '\n');
f_mode(wisdom, 2048);
f_byte(wisdom, '\n');
f_mode(wisdom, 4096);
f_byte(wisdom, '\n');
f_mode(wisdom, 8192);
f_byte(wisdom, '\n');
f_mode(wisdom, 16384);
f_byte(wisdom, '\n');
f_mode(wisdom, 32768);
f_byte(wisdom, '\n');
f_mode(wisdom, 65536);
f_byte(wisdom, '\n');
f_mode(wisdom, 131072);
f_byte(wisdom, '\n');
f_mode(wisdom, 262144);
f_byte(wisdom, '\n');
f_mode(wisdom, 524288);
f_byte(wisdom, '\n');
f_mode(wisdom, 1048576);
f_byte(wisdom, '\n');

Now that we have equipped the mankind with such valuable information we'll go on and close the file:

f_close(wisdom);