Algaja Cee progeja lõbud
Mõtlesin et värskendan oma väheseid Cee teadmisi läbi kasuliku. Kirjutan sellise pisikese poomise mängu. Alustan siis tasapisi basic asjadest.
#include
#define INPUTTEXT "Sisesta täht nr "
#define TRIES 3
main () {
char a[10];
char b;
int count = 0;
while (TRIES > count) {
printf( INPUTTEXT "%d :\n", count );
scanf( "%s", b);
a[count] = b;
++count;
}
return 0;
}
Hetkel on siis tulemus selline:
[10:43:31 margusja@Irack:~/Documents/poomine ] $ gcc poomine.c -o poomine
[10:43:33 margusja@Irack:~/Documents/poomine ] $ ./poomine
Sisesta täht nr 0 :
a
Segmentation fault
[10:43:36 margusja@Irack:~/Documents/poomine ] $ gd
gdb gdiffmk gdk-pixbuf-csource gdk-pixbuf-query-loaders gdlib-config
[10:43:36 margusja@Irack:~/Documents/poomine ] $ gd
gdb gdiffmk gdk-pixbuf-csource gdk-pixbuf-query-loaders gdlib-config
[10:43:36 margusja@Irack:~/Documents/poomine ] $ gdb ./poomine
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “i386-apple-darwin”…Reading symbols for shared libraries … done
(gdb) run
Starting program: /Users/margusja/Documents/poomine/poomine
Reading symbols for shared libraries ++. done
Sisesta täht nr 0 :
a
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xffffffbf
0x96d97fc1 in __svfscanf_l ()
(gdb)
Nii uus katse ehk on string tüüpidega mingi jama:
#include
#define INPUTTEXT "Sisesta täht nr "
#define TRIES 3
main () {
long a[10];
int b;
int count = 0;
while (TRIES > count) {
printf( INPUTTEXT "%d :\n", count );
scanf( "%d", b);
a[count] = b;
++count;
}
[08:55:03 margusja@Irack:~/Documents/poomine ] $ gdb poomine
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “i386-apple-darwin”…Reading symbols for shared libraries … done
(gdb) run
Starting program: /Users/margusja/Documents/poomine/poomine
Reading symbols for shared libraries ++. done
Sisesta täht nr 0 :
1
Sisesta täht nr 1 :
2
Sisesta täht nr 2 :
3
Program exited normally.
(gdb)
(gdb) quit
return 0;
}
NB! kui gdb kasu ootate siis kompileerida -g võtmega.
Hetkel käitub minu programm mitte just nii nagu mina soovin. Nagu altpoolt näha on ei oodata täht nr 1’te.
[10:59:29 margusja@Irack:~/Documents/poomine ] $ ./poomine
Sisesta täht nr 0 :
a
Sisesta täht nr 1 :
Sisesta täht nr 2 :
b
Sisesta täht nr 0 – (null):
Sisesta täht nr 1 – (null):
Sisesta täht nr 2 – (null):
Siinkohal tuleb appi gdb:
[11:01:52 margusja@Irack:~/Documents/poomine ] $ gdb ./poomine
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “i386-apple-darwin”…Reading symbols for shared libraries … done
(gdb) l 10
5
6 main () {
7 char a[10];
8 char b;
9 int count = 0;
10
11 while (TRIES > count) {
12 printf( INPUTTEXT “%d :\n”, count );
13 b = getchar();
14 ++count;
(gdb)
15 }
16
17 count = 0;
18 while (TRIES > count) {
19 printf( INPUTTEXT “%d – %s:\n”, count, a[count] );
20 ++count;
21 }
22
23
24 return 0;
(gdb) b 14
Breakpoint 1 at 0x1f7d: file poomine.c, line 14.
(gdb) run
Starting program: /Users/margusja/Documents/poomine/poomine
Reading symbols for shared libraries ++. done
Sisesta täht nr 0 :
a
Breakpoint 1, main () at poomine.c:14
14 ++count;
(gdb) disp b
1: b = 97 ‘a’
(gdb) continue
Continuing.
Sisesta täht nr 1 :
Breakpoint 1, main () at poomine.c:14
14 ++count;
1: b = 10 ‘\n’
(gdb) continue
Continuing.
Sisesta täht nr 2 :
b
Breakpoint 1, main () at poomine.c:14
Nagu näha on satub nr 1 sloti \n ehk reavahetus.
14 ++count;
1: b = 98 ‘b’
—
Seega tuleb reavahetusest lahti saada. See on stringi sisestamises üks väga levinud probleem.
[22:43:54 margusja@Irack:~/Documents/poomine ] $ gdb ./poomine
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “i386-apple-darwin”…Reading symbols for shared libraries … done
(gdb) l
1 #include
2 #include
3
4 #define INPUTTEXT “Sisesta täht nr ”
5 #define TRIES 3
6
7 main () {
8 char a[10];
9 char b[20];
10 int count = 0;
(gdb)
11
12 while (TRIES > count) {
13 printf( INPUTTEXT “%d :\n”, count );
14 fgets (b, sizeof b, stdin );
15 char *newline = strchr(b, ‘\n’);
16 *newline = ‘\0’;
17 a[count] = b[0];
18 ++count;
19 }
20
(gdb)
21 printf(“%s:\n”,a );
22
23 return 0;
24 }
(gdb)
(gdb) b 18
Breakpoint 1 at 0x1fb5: file poomine.c, line 18.
(gdb) run
Starting program: /Users/margusja/Documents/poomine/poomine
Reading symbols for shared libraries ++. done
Sisesta täht nr 0 :
a
Breakpoint 1, main () at poomine.c:18
18 ++count;
(gdb) disp b[0]
Invalid character ‘?’ in expression.
(gdb) disp b[0]
1: b[0] = 97 ‘a’
(gdb) disp a[0]
2: a[0] = 97 ‘a’
(gdb) cont
Continuing.
Sisesta täht nr 1 :
b
Breakpoint 1, main () at poomine.c:18
18 ++count;
2: a[0] = 97 ‘a’
1: b[0] = 98 ‘b’
(gdb) disp a[1]
3: a[1] = 98 ‘b’
(gdb) cont
Continuing.
Sisesta täht nr 2 :
c
Breakpoint 1, main () at poomine.c:18
18 ++count;
3: a[1] = 98 ‘b’
2: a[0] = 97 ‘a’
1: b[0] = 99 ‘c’
(gdb) disp a]
A syntax error in expression, near `]’.
(gdb) disp a[2]
4: a[2] = 99 ‘c’
(gdb) cont
Continuing.
abc:
Program exited normally.
(gdb)
Natuke langevarjundust
wings vabaotsad
WTF!
Meremuuseumis
Kuna sai tasuta siis raskel ajal kasutasime harival eesmärgil ära. Paar klõpsu.
Evelin Ilvese ametlik ihuinstruktor
Eesti esileedi avastas enda jaoks uue hobi – langevarjunduse. Mul on au ennast esitleda Eesti esileedi ihuinstruktorina.
netcat
Fantastiliselt lõbus tööriist. Sellega võib tunde mängida. Samas on ka asendamatu turva ja võrguliikluse testimisel.
Paar pilti minu lõbutsemisest.
LFS and SSHD
Minu LFS maailmas on uus samm. Mu hädine linuxi pojake omab oskust kuulata sshd porti. Mida kõike head see endas kaasab? Eelkõige seda, et ma ei pea enam mingi parallels konsooli peal sodima. Saan oma lemmiks SSH kliendiga teha oma LFS masinasse sshd.
Õhtusöök-0.3-4
Täna õhtul selgus et tuleb minul õhtusöök teha. Poes selgus et eelkompileeritud komponendid meie distributsiooniga (VarMar) ei sobinud. Üle jäi ainult variant siis sortsust kompileerida.
Valitud sai siis külmutatud aedviljad-1.0-2.src ning lihaviilud-3.2-3.src.
Kodus otsisin ülesse kompilaatori (pann-2.3-deflon) Selgus et pakk aedviljad-1.0-2.src vajas kompileerimiseks pakki lihaviilud-3.2-3.src. Nii sai ka tehtud. Kompileerimise protsess oli suhteliselt lihtne. Paar korda pidin sekkuma debuugeriga (puulusikas).
Tulemus oli rahuldav.
Tänkjas
Täna oli selline päev kus Kristel tuli ja teatas et kohuke oli “Tänkjas” Ja ta oli püsti imestunud kui mina ega Varulla polnud sellest sõnast kuulnud. Tegime siis katsetuse ja küsisime #Skydive kanalilt ka et kas keegi teab. Tulemis oli järgmine.
Varulane: mehed
[6:34pm] Varulane: kes teab mis on TÄNKJAS
[6:34pm] Varulane: ull ei küsi anka käest
[6:34pm] ull: nätske
[6:34pm] CD-R: nüüd küll spikerdasid
[6:35pm] ull: jah
[6:35pm] ull: sry
[6:35pm] ull: ma muidu küll ei teadnud
[6:35pm] ull: oleks pakkund et nii ütleb margusja “aitähh”, kui ise parasjagu lätis või leedus on
[6:36pm] CD-R: irw
[6:47pm] Varulane: irwwwwwwwwwwwwww
[6:50pm] ull: anka ei teadnud, pakkus et mida gi klimpjat
duke joined the chat room.
[7:09pm] ull left the chat room. (Read error: Connection reset by peer)
[7:10pm] ull joined the chat room.
[7:12pm] Varulane: uke
[7:12pm] Varulane: duke
[7:12pm] duke: jah
[7:12pm] duke: void oelda ka dukepolopolous
[7:12pm] Varulane: defineeri tänkjas
[7:12pm] duke: misasi?
[7:13pm] Varulane: TÄNKJAS
[7:13pm] duke: kas sulle tundub et ma peaks teadma seda?
[7:13pm] Varulane: no paku midagi
[7:14pm] Varulane: googeldada ei tohi
[7:14pm] duke: naiserahvas, kelle kehakuju meenutab tanki?
Varulla suutis leida laulusalmile analoogi:
Hei pöialpoisid!
Dilidili, dilidili , dili dili dili dili don – nagu ikka pöialpoisse meidki seitse on!Pesamuna Hellik, teadlane Tarkur, Tänkjas ja Nälkjas, mina olen Siipel, ma jõumees Junnu.sai kokku kuus -tõesti kuus, veel puudu üks-tõesti üks, see vahava Dilidon, kes pealik meil on!Dilidili, dilidili , dili dili dili dili don