--- Log opened Fri Dec 05 00:00:00 2008 |
00:10 | | You're now known as TheWatcher[T-2] |
00:15 | | You're now known as TheWatcher[zZzZ] |
00:30 | | AnnoDomini [~farkoff@Nightstar-27855.neoplus.adsl.tpnet.pl] has quit [Quit: You can't eat someone's pet hamburger!] |
02:56 | | Pink [~none@Nightstar-7066.dyn.optonline.net] has joined #code |
06:22 | | gnolam [lenin@79.136.60.ns-4387] has quit [Quit: Z?] |
07:13 | | Vornicus is now known as Vornicus-Latens |
08:17 | | AnnoDomini [~farkoff@Nightstar-29346.neoplus.adsl.tpnet.pl] has joined #Code |
08:17 | | mode/#code [+o AnnoDomini] by ChanServ |
09:06 | | McMartin [~mcmartin@Nightstar-14680.dsl.pltn13.sbcglobal.net] has quit [Quit: rebooting IRC machine] |
09:45 | | Vornotron [~vorn@Admin.Nightstar.Net] has joined #code |
09:45 | | Vornicus-Latens [~vorn@Admin.Nightstar.Net] has quit [Ping Timeout] |
10:01 | | You're now known as TheWatcher |
12:51 | | gnolam [lenin@79.136.60.ns-4387] has joined #Code |
12:51 | | mode/#code [+o gnolam] by ChanServ |
14:26 | <@Attilla> | Hmm. Is there an easy way to get a simple random number of either 1 or 0 in C? |
14:33 | <@gnolam> | rand()%2. |
14:34 | <@Attilla> | Ah, there we are. It's just it doesn't like having anything inside the brackets :( |
14:34 | | alaric [~grossroot@Nightstar-2147.hackthisbox.org] has joined #code |
14:34 | < alaric> | hi |
14:34 | <@gnolam> | ? |
14:35 | < alaric> | just a hello to all programmers :) |
14:35 | <@gnolam> | Oh, not you. Attilla. :) |
14:36 | <@Attilla> | Well some languages have the interior of rand() define the point it ends at, etc. etc. |
14:36 | <@Attilla> | So rand(100) would get a number from 0 to 99 |
14:36 | < alaric> | :-) |
15:03 | <@gnolam> | Ah. |
15:14 | <@gnolam> | Word of the day: "Adjustment sledgehammer". |
15:15 | <@gnolam> | (An important tool carried by all VAZ/Lada owners) |
15:19 | <@AnnoDomini> | Methinks that UAZ. |
15:24 | <@Attilla> | Ach, this objective is silly. I have to input the probability of getting a 1 that I want the rangen to operate on. I guess I better give it a big range and count the probably as a scale on the if-then-else |
15:25 | <@gnolam> | AnnoDomini: Nah. The UAZs have a reputation for reliability. |
15:28 | <@gnolam> | Attilla: Just skip the mod. |
15:29 | <@gnolam> | rand() returns a value between 0 and RAND_MAX. |
16:15 | | MyCatVerbs [~mycatverb@Nightstar-13709.lurkingfox.co.uk] has quit [Client exited] |
16:36 | | Attilla [~The.Attil@Nightstar-9469.cdif.cable.ntl.com] has quit [Ping Timeout] |
16:39 | | Attilla [~The.Attil@Nightstar-9469.cdif.cable.ntl.com] has joined #code |
16:39 | | mode/#code [+o Attilla] by ChanServ |
16:44 | | alaric [~grossroot@Nightstar-2147.hackthisbox.org] has quit [Quit: Lost terminal] |
16:50 | | grossroot [~grossroot@Nightstar-2147.hackthisbox.org] has joined #code |
17:07 | | You're now known as TheWatcher[afk] |
17:57 | <@Attilla> | Gah, how do you get an if conditional to work on a string? I mean shouldn't it be something like if (String == 'string') ? |
17:57 | <@Attilla> | Or "string"? |
17:58 | < ToxicFrog> | What language? |
17:58 | <@Attilla> | C |
17:58 | < ToxicFrog> | Oh, you wish it were that simple. |
17:59 | < ToxicFrog> | Recall that in C, strings are character arrays and arrays are pointers. |
17:59 | <@Attilla> | Oh that stuff |
17:59 | < ToxicFrog> | == on pointer types compares to see if they point to the same address. |
18:00 | < ToxicFrog> | So stringA == stringB is true if A is B, but not otherwise, include the case where A is equal to B. |
18:00 | < ToxicFrog> | (*stringA == *stringB) looks tempting, but actually just compares the first characters (recall that the formal type is char*) |
18:00 | < ToxicFrog> | What you actually want is the strcmp or strncmp functions. |
18:00 | < ToxicFrog> | int strcmp(const char * A, const char * B) |
18:01 | < ToxicFrog> | Returns an integer indicating the difference between them; 0 if they are equal, <0 if A < B, >0 if A > B. |
18:01 | < ToxicFrog> | The man page has the juicy details. |
18:02 | < ToxicFrog> | And now, shower |
18:02 | < grossroot> | or switch to c++ and use std::string |
18:06 | <@Attilla> | Curses, a segmentation fault has appeared :( |
18:07 | | MyCatVerbs [~mycatverb@Nightstar-13709.lurkingfox.co.uk] has joined #code |
18:07 | | mode/#code [+o MyCatVerbs] by ChanServ |
18:09 | <@Attilla> | scanf("%s", String); would input a string as variable String right? (You don't need a pointer do you? (Not that it matters, with or without the & it still gives me a seg fault) |
18:11 | < grossroot> | must be something like buffer overflow or something. i think, that String was too small or were not malloc()ed |
18:11 | <@jerith> | Attilla: String needs to be an existing buffer. |
18:11 | <@jerith> | char String[256]; or something. |
18:11 | <@jerith> | You also need to give scanf() a pointer to String. |
18:12 | <@jerith> | I'm pretty sure scanf() doesn't do any kind of range checking, so it's a buffer overflow waiting to happen, too. |
18:14 | | MyCatVerbs [~mycatverb@Nightstar-13709.lurkingfox.co.uk] has quit [Quit: Rejoice, mortals, for now my IRC client will die about six times less often! \o/] |
18:14 | | MyCatVerbs [~mycatverb@Nightstar-13709.lurkingfox.co.uk] has joined #code |
18:14 | | mode/#code [+o MyCatVerbs] by ChanServ |
18:15 | | You're now known as TheWatcher |
18:15 | | MyCatVerbs [~mycatverb@Nightstar-13709.lurkingfox.co.uk] has quit [Quit: Cease rejoicing. Count to twenty, then resume rejoiceful state. Mortals.] |
18:16 | | MyCatVerbs [~mycatverb@Nightstar-13709.lurkingfox.co.uk] has joined #code |
18:16 | | mode/#code [+o MyCatVerbs] by ChanServ |
18:20 | < ToxicFrog> | Attilla: what jerith said. |
18:20 | < ToxicFrog> | Read the man page for scanf. |
18:20 | < ToxicFrog> | And then use fgets instead, if possible. |
18:21 | < ToxicFrog> | Although, if you're using gnu89 or gnu99 (not c99), the 'a' modifier will have it auto-allocate the string for you |
18:22 | < ToxicFrog> | And it can do range checking: |
18:23 | < ToxicFrog> | char buf[256]; scanf("?s", &buf); |
18:23 | < ToxicFrog> | With the a extension: |
18:23 | < ToxicFrog> | char * buf; scanf("%as", &buf); |
18:23 | < ToxicFrog> | ...pretend the first one was scanf("%255s", buf) |
18:57 | | McMartin [~mcmartin@Nightstar-14680.dsl.pltn13.sbcglobal.net] has joined #code |
18:57 | | mode/#code [+o McMartin] by ChanServ |
19:07 | | grossroot [~grossroot@Nightstar-2147.hackthisbox.org] has quit [Quit: leaving] |
19:24 | | grossroot [~grossroot@Nightstar-2147.hackthisbox.org] has joined #code |
19:55 | | Vornucopia [~vorn@Admin.Nightstar.Net] has joined #code |
19:57 | | Vornotron [~vorn@Admin.Nightstar.Net] has quit [Ping Timeout] |
20:11 | | Vornotron [~vorn@Admin.Nightstar.Net] has joined #code |
20:13 | | Vornucopia [~vorn@Admin.Nightstar.Net] has quit [Ping Timeout] |
20:43 | | Vornucopia [~vorn@Admin.Nightstar.Net] has joined #code |
20:44 | | Vornotron [~vorn@Admin.Nightstar.Net] has quit [Ping Timeout] |
21:54 | | grossroot is now known as grossroot[idle] |
22:17 | | Vornotron [~vorn@Admin.Nightstar.Net] has joined #code |
22:19 | | Vornucopia [~vorn@Admin.Nightstar.Net] has quit [Ping Timeout] |
22:43 | | Vornucopia [~vorn@Admin.Nightstar.Net] has joined #code |
22:45 | | Vornotron [~vorn@Admin.Nightstar.Net] has quit [Ping Timeout] |
23:27 | | Vornotron [~vorn@Admin.Nightstar.Net] has joined #code |
23:28 | | Vornucopia [~vorn@Admin.Nightstar.Net] has quit [Ping Timeout] |
--- Log closed Sat Dec 06 00:00:12 2008 |