{{{#!IRC [Jun 22 17:06:12] juju2143, I'm so sorry to be bothering you yet again but ping [Jun 22 17:06:40] pong? [Jun 22 17:07:40] well, to publicize the class, we need either a short description or even maybe something about your experience related to C#.. something to say, basically, to go towards publicizing [Jun 22 17:14:53] juju2143, ^ [Jun 22 17:20:43] ah ok [Jun 22 17:21:14] bah this is an introduction to C# [Jun 22 17:22:11] learnt it at school [Jun 22 17:22:13] etc. [Jun 22 19:03:43] bgs100, was there any homework? [Jun 22 19:04:28] one sec * bgs100 [Jun 22 19:05:34] attempts to recall... [Jun 22 19:06:04] pedro3005, Don't think so [Jun 22 19:06:11] hah! [Jun 22 19:06:17] Hiya seidos [Jun 22 19:06:20] bgs100, did you continue the class after I left? [Jun 22 19:06:52] Not really [Jun 22 19:07:19] ok [Jun 22 19:07:30] We talked about prine based number systems and binary [Jun 22 19:08:15] hey seidos [Jun 22 19:09:34] brb [Jun 22 19:10:53] back [Jun 22 19:10:55] Sooooooo [Jun 22 19:11:06] Are we all ready to begin? [Jun 22 19:11:08] seidos, pedro3005 ? [Jun 22 19:11:21] ARE YOU READY [Jun 22 19:11:27] :p [Jun 22 19:11:29] ready [Jun 22 19:11:31] TO ROCK?! [Jun 22 19:11:47] noo... >:( [Jun 22 19:11:57] I WANNA ROCK! YEAAHH ROCK YEEAHH ROCK YEEAHH [Jun 22 19:12:02] DA NA NA [Jun 22 19:12:11] bgs100, http://www.youtube.com/watch?v=2JSgjQHPrTc [Jun 22 19:12:12] *wicked guitar solo* [Jun 22 19:12:27] oh [Jun 22 19:12:29] :P [Jun 22 19:12:46] seidos, ? [Jun 22 19:14:00] ......... [Jun 22 19:14:12] I'll assume seidos will be here shortly [Jun 22 19:14:16] Now [Jun 22 19:14:23] Without Further Ado [Jun 22 19:14:33] THE C CLASS [Jun 22 19:14:54] -=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-= MAY ZE C CLASS =-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=- [Jun 22 19:15:02] -=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-= BEGIN =-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=- [Jun 22 19:15:29] So ya [Jun 22 19:15:43] Now [Jun 22 19:15:51] seidos, pedro3005 You pretty much know the base language [Jun 22 19:16:01] So give yourself a hearty pat on the back * pedro3005 [Jun 22 19:16:04] dances around the room [Jun 22 19:16:09] or that [Jun 22 19:16:22] whatever *float*s your boat xD [Jun 22 19:16:48] Get it? Get it? *elbows pedro3005* [Jun 22 19:16:54] you've used that one before [Jun 22 19:16:59] No [Jun 22 19:17:04] yes you have [Jun 22 19:17:05] before I said No pun intended [Jun 22 19:17:13] Thsi time it's completely intended [Jun 22 19:17:14] well, still [Jun 22 19:17:18] This* [Jun 22 19:17:49] So [Jun 22 19:17:55] Now, we will be focusing upon: [Jun 22 19:18:05] ***THE STANDARD LIBRARY*** [Jun 22 19:18:09] *Angels sing* [Jun 22 19:19:19] I read it more in a devilish frightening tone [Jun 22 19:19:28] ... [Jun 22 19:19:34] Well fix that [Jun 22 19:20:11] The standard library is sort of like the modules that Python always comes with. If it's normal C (e.g. your not building stuff for a kernel or embedded device), you'll have the standard library. [Jun 22 19:21:43] So [Jun 22 19:21:57] As you (*pings pedro3005 and seidos again*) know, [Jun 22 19:22:25] we have been using the standard library in every example thus far. [Jun 22 19:22:32] yes [Jun 22 19:23:05] There's not that much you can do without the standrad library, unless you use assembly with C. [Jun 22 19:23:20] stdio.h is part of the standard library [Jun 22 19:24:17] pedro3005, Your book should have a reference to the standard library in Appendix B [Jun 22 19:24:43] yes [Jun 22 19:25:07] For seidos: http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html looks pretty good [Jun 22 19:25:25] stdio, ctype, string, math, stdlib, assert, stdarg, setjmp, signal, time, limits, float [Jun 22 19:26:17] anyway. [Jun 22 19:26:30] I was thinking that today, we would start with string.h [Jun 22 19:27:11] string.h consists of functions useful for doing things with strings, as the name Oh-So-Discreetly implies [Jun 22 19:28:05] So [Jun 22 19:28:41] Allocating char pointers for strings yourself was mentioned yesterday. [Jun 22 19:28:57] However, [Jun 22 19:29:06] if you allocate it yourself and such, [Jun 22 19:29:13] how can you assign it to a string nicely? [Jun 22 19:29:23] If you do: [Jun 22 19:29:37] char *string = malloc(5); [Jun 22 19:29:46] later saying: [Jun 22 19:29:52] string = "book"; [Jun 22 19:29:56] obviously won't work [Jun 22 19:30:11] since it just changes the address string has. [Jun 22 19:30:16] string = {'b', 'o', 'o', 'k'} [Jun 22 19:30:17] ? [Jun 22 19:30:21] it's rather not obvious at all [Jun 22 19:30:26] no [Jun 22 19:30:27] Same thing, except without a '\0' [Jun 22 19:30:38] Snova, It's a reassignment. [Jun 22 19:30:49] *shrugs* [Jun 22 19:30:53] there is no way to assign to an array like that [Jun 22 19:30:56] Also, hai [Jun 22 19:31:01] hello [Jun 22 19:31:06] did you read the malloc part earlier? [Jun 22 19:31:12] uh, yes? [Jun 22 19:31:43] malloc isn't relevant to this point; you can not assign the contents of an array except when initially declaring it [Jun 22 19:31:44] still no way? [Jun 22 19:31:50] Oh yeah * bgs100 [Jun 22 19:31:55] facepalms [Jun 22 19:31:59] i.e. int x[5] = {1, 2, 3, 4, 5}; will work but you can't change the whole thing later on [Jun 22 19:32:15] Well, now there's two reasons it would not work. xP [Jun 22 19:32:41] Snova, isn't there someway to tell it to "forget" about the old x and just declare it again? [Jun 22 19:32:42] "char* string = malloc(5); string = "book";" doesn't change the contents of the original allocation; it changes the pointer "string" to reference the constant string "book" [Jun 22 19:32:45] it's also a memory leak [Jun 22 19:32:48] pedro3005: no [Jun 22 19:33:02] Snova, That was my point... [Jun 22 19:33:29] god I hate C [Jun 22 19:33:33] :P [Jun 22 19:33:34] :| [Jun 22 19:34:37] you can't do anything [Jun 22 19:34:41] but go on [Jun 22 19:34:43] ... [Jun 22 19:34:56] C has been called a "portable assembly" [Jun 22 19:35:17] pedro3005, Apparently, you can, considering many other languages' interpreters/compilers are written in it... [Jun 22 19:35:46] But Aaaannnyyywaaayyy [Jun 22 19:35:54] So yeah [Jun 22 19:37:05] Anyway [Jun 22 19:37:10] You could do this: [Jun 22 19:37:21] char *string = malloc(5); [Jun 22 19:37:36] strcpy(string, "book"); [Jun 22 19:37:40] Correct, Snova? [Jun 22 19:37:52] yes [Jun 22 19:37:57] Okay [Jun 22 19:38:01] Good :p [Jun 22 19:39:07] pedro3005, (since seidos doesn't seem to be present) strcpy take two char pointers/arrays and copies the contents of the second (including the '\0') into the first. [Jun 22 19:39:38] so basically it does string[0] = 'b'; etc? [Jun 22 19:39:46] strcpy = string copy, as you probably guessed. [Jun 22 19:39:53] pedro3005: pretty much [Jun 22 19:40:13] okay [Jun 22 19:40:13] pedro3005, Or rather, string[0] = secondstring[0], but in this case yeah [Jun 22 19:41:09] Also [Jun 22 19:41:37] I should mention that for many str functions there are also strn functions, [Jun 22 19:42:09] what does that mean? [Jun 22 19:42:21] I'm typing :P [Jun 22 19:42:37] Those take an extra argument that makes it only do whatever for n characters [Jun 22 19:42:41] For example, [Jun 22 19:43:04] strncpy will only copy n characters to the first string [Jun 22 19:44:08] From the manpage for strcpy/strncpy: "The strncpy() function is similar, except that at most n bytes of src are copied." [Jun 22 19:44:22] src being the second string [Jun 22 19:44:28] pedro3005, Okay? [Jun 22 19:44:31] example? [Jun 22 19:45:05] char *string = malloc(4); [Jun 22 19:45:17] strncpy(string, "book", 4); [Jun 22 19:45:19] HOWEVER [Jun 22 19:45:27] This will cut off the '\0' at the end [Jun 22 19:45:57] oh, so always +1 [Jun 22 19:46:06] pedro3005, I might be used to make sure that the function doesn't copy past the first string's actual length. [Jun 22 19:46:15] pedro3005, er that's not the point :p [Jun 22 19:46:21] s/I/It/ [Jun 22 19:46:41] oh, ok [Jun 22 19:46:52] this is somewhat confusing but alright [Jun 22 19:47:34] Okay [Jun 22 19:47:43] Next, we have strcat [Jun 22 19:48:21] Example: [Jun 22 19:48:46] char *string = malloc(9); [Jun 22 19:49:00] strcpy(string, "book"); [Jun 22 19:49:09] strcat(string, "club"); [Jun 22 19:49:16] string ends up being "bookclub" [Jun 22 19:49:54] so it adds it before the '\0' and makes sure there is not two '\0' at the end? [Jun 22 19:50:25] Yeah, pretty much. [Jun 22 19:50:41] Or rather just overwrites the first '\0' with the first character of the second string [Jun 22 19:50:54] and then copies the second strings '\0' [Jun 22 19:51:32] I see [Jun 22 19:51:40] But yeah, it appends string2 to string1, and if they're "normal" strings there won't be two '\0''s [Jun 22 19:51:47] So [Jun 22 19:51:55] Oh [Jun 22 19:52:02] And there's a "n" version of that too [Jun 22 19:52:15] Where only "n" characters from string2 are appended [Jun 22 19:53:17] Okay [Jun 22 19:53:18] strchr [Jun 22 19:53:18] ok [Jun 22 19:54:38] char *string = malloc(7); [Jun 22 19:55:09] strcpy(string, "cookie"); [Jun 22 19:55:31] char *otherstring = strchr(string, 'o'); [Jun 22 19:55:42] otherstring should now be the string "ookie" [Jun 22 19:55:55] However [Jun 22 19:56:01] Well [Jun 22 19:56:02] First [Jun 22 19:56:44] pedro3005, strchr returns a pointer to the first occurrence of the character ('o') in the string [Jun 22 19:57:02] Okay? [Jun 22 19:57:17] ... [Jun 22 19:57:23] brb, I have to... brush my teeth [Jun 22 19:57:27] ............ [Jun 22 19:57:34] well okay then [Jun 22 19:57:45] Don't take too long :P [Jun 22 19:57:48] (jk) [Jun 22 19:59:12] bgs100, back [Jun 22 19:59:52] okay [Jun 22 19:59:59] pedro3005, So Okay about strchr? [Jun 22 20:00:09] so strchr copies it starting from 'o'? [Jun 22 20:00:14] Uhh [Jun 22 20:00:23] I was about to get to that... [Jun 22 20:00:26] It doesn't copy it [Jun 22 20:00:41] oh [Jun 22 20:00:41] right [Jun 22 20:00:45] it returns it [Jun 22 20:00:56] If you changed string more than the first character, otherstring would change too [Jun 22 20:01:01] And vice versa [Jun 22 20:01:17] oh, because it returns a poinnnnnnter * bgs100 [Jun 22 20:01:31] gives pedro3005 a star [Jun 22 20:01:36] well [Jun 22 20:01:38] not quite [Jun 22 20:01:45] If it copied it, [Jun 22 20:01:53] It would still be returning a pointer * bgs100 [Jun 22 20:02:00] takes away half of the star [Jun 22 20:02:02] just a different one [Jun 22 20:02:15] Yea [Jun 22 20:03:59] Also [Jun 22 20:04:04] There is strrchr [Jun 22 20:04:20] It returns a pointer to the *last* occurence of a char [Jun 22 20:04:22] Like [Jun 22 20:04:26] If we had said: [Jun 22 20:04:35] char *otherstring = strrchr(string, 'o'); [Jun 22 20:04:37] instead [Jun 22 20:04:44] otherstring would be "okie" [Jun 22 20:04:52] BTW [Jun 22 20:05:14] Both of these functions return NULL (secretly 0) if they can't find any of that character [Jun 22 20:05:57] pedro3005, 'kay? [Jun 22 20:06:00] okay [Jun 22 20:06:29] good then [Jun 22 20:06:34] On to strcmp [Jun 22 20:07:07] String compare compares to strings [Jun 22 20:07:47] two* [Jun 22 20:07:53] lexicographically [Jun 22 20:09:20] Which is a very fancy term that means something similar to alphabetical order [Jun 22 20:09:28] pedro3005, [Jun 22 20:09:57] If string1 is "less than" string2 (e.g. "a" < "b"), strcmp returns less than 0 [Jun 22 20:10:22] If string1 is "greater than" string2 (e.g. "z" > "y"), strcmp returns more than 0 [Jun 22 20:10:30] what about [Jun 22 20:10:34] "2" - "a" [Jun 22 20:10:37] which "wins"? [Jun 22 20:10:49] If the two strings are equal (this is probably what strcmp is primarily used for), it returns 0 [Jun 22 20:11:09] pedro3005, [Jun 22 20:11:27] I think it uses your character sets numbers for each [Jun 22 20:11:51] pedro3005, 2 is less than a, methinks [Jun 22 20:12:11] ok [Jun 22 20:12:13] Ah crap [Jun 22 20:12:17] I have to go for a few [Jun 22 20:12:36] 8sigh* [Jun 22 20:12:37] it's cool [Jun 22 20:12:42] I'll program something * bgs100 [Jun 22 20:12:47] shakes fist at parents :P [Jun 22 20:12:52] bai [Jun 22 20:12:57] bbs [Jun 22 20:57:34] Baaack [Jun 22 20:57:39] pedro3005, Ping [Jun 22 20:57:50] hey [Jun 22 20:57:53] seidos is here too [Jun 22 20:59:55] ... I think [Jun 22 21:01:19] bgs100, >:( [Jun 22 21:05:37] HAI [Jun 22 21:05:39] hey [Jun 22 21:05:44] I'll have to read the logs of the class [Jun 22 21:05:45] seidos, Read the logs :P [Jun 22 21:06:09] 22 isn't posted yet [Jun 22 21:06:13] but I'll check back later [Jun 22 21:08:01] seidos, I have it [Jun 22 21:08:04] i'll paste them for you [Jun 22 21:08:50] seidos, http://paste.pocoo.org/show/228767/ [Jun 22 21:09:55] bgs100, do you intend to continue on strings? [Jun 22 21:12:33] Yes [Jun 22 21:12:42] But not right now, unfortunatley :/ [Jun 22 21:14:47] too bad there aren't videos on learning C [Jun 22 21:14:55] seidos, there are [Jun 22 21:14:57] too bad I can't just upload it all into my brain [Jun 22 21:15:08] pedro3005, have you looked at any of them? [Jun 22 21:15:17] nah [Jun 22 21:15:24] but I intend to.. some day [Jun 22 21:15:40] alright bgs100, bye [Jun 22 21:15:50] Well [Jun 22 21:15:52] Actually [Jun 22 21:15:55] i may be able to cintunue [Jun 22 21:16:00] continue* [Jun 22 21:16:15] Anyway [Jun 22 21:16:47] bgs100: it's been thirty seconds! [Jun 22 21:17:09] ? [Jun 22 21:17:19] strcmp is most often used for seeing if two strings are equal [Jun 22 21:17:44] isn't that the only thing it does? :p [Jun 22 21:18:04] I already talked about that [Jun 22 21:18:32] Look up. [Jun 22 21:19:54] I laready detailed the usage, I'm just adding on. [Jun 22 21:19:57] already* [Jun 22 21:20:02] Anyway [Jun 22 21:20:10] Example: [Jun 22 21:20:18] Ohwait [Jun 22 21:20:25] I should also mention [Jun 22 21:21:02] scanf can read in strings. It will continue until there is whitespace (a space, newline, or tab). [Jun 22 21:21:11] Continuing with the example: [Jun 22 21:21:40] char *string; [Jun 22 21:22:30] er [Jun 22 21:23:25] brb :p [Jun 22 21:25:23] he'll be back by Christmas [Jun 22 21:26:12] Back [Jun 22 21:26:19] Merry Christmas all! * bgs100 [Jun 22 21:26:31] gives pedro3005 the gift of a bonk on the head [Jun 22 21:26:42] :P [Jun 22 21:27:21] Okay [Jun 22 21:27:27] char string[21]; [Jun 22 21:28:00] printf("ENTER THE SUPER SECRET PASSWORD OR BE EXTERMINATED! "); [Jun 22 21:28:34] scanf("%s", &string); [Jun 22 21:29:04] if (strcmp(string, "happychristmas") == 0) { [Jun 22 21:30:00] puts("CORRECT. YOU MAY NOW LIVE SO YEAH ANYWAY."); [Jun 22 21:30:10] } else { [Jun 22 21:30:29] puts("EXTERMINATE! EXTERMINATE!"); [Jun 22 21:30:30] } [Jun 22 21:30:45] sorry for being kind of slow. [Jun 22 21:30:52] no problem [Jun 22 21:31:02] So, that's strcmp [Jun 22 21:31:26] Hmm [Jun 22 21:32:04] doesn't C have classes? [Jun 22 21:32:25] that's probably structs * pedro3005 [Jun 22 21:32:30] fails [Jun 22 21:33:36] Yes, pedro3005 does [Jun 22 21:33:57] :( [Jun 22 21:34:11] :p [Jun 22 21:34:13] Well [Jun 22 21:35:34] You know, I'm not going to go through every single function in the standard library... [Jun 22 21:35:53] I suggest this: [Jun 22 21:35:54] bgs100, is it or is it not? [Jun 22 21:36:07] What? [Jun 22 21:36:11] classes [Jun 22 21:36:15] ... [Jun 22 21:36:26] No, C does not have "classes" [Jun 22 21:36:32] Anyway [Jun 22 21:36:50] For learning about the standard library, I suggest this: [Jun 22 21:37:01] Looking through this page: http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html [Jun 22 21:37:06] And [Jun 22 21:38:06] For more of an in-depth description of a function (usually), related functions, and sometimes examples of usage or implementation, I suggest consulting manpages: [Jun 22 21:38:16] By running: man [Jun 22 21:38:18] bgs100, oh, so that's what stdlib means? [Jun 22 21:38:18] pedro3005: no [Jun 22 21:38:26] If that function happens to also be a command [Jun 22 21:38:43] Snova, ... quick answer huh [Jun 22 21:38:46] 1 second later [Jun 22 21:38:48] :P [Jun 22 21:39:09] pedro3005, stdlib does stand for standard library, but stdlib.h does not mean the whole library or any such thing [Jun 22 21:39:26] Also [Jun 22 21:39:31] so why is it called stdlib.h? they were running out of names? [Jun 22 21:39:41] Uh sure we can go with that :p [Jun 22 21:39:45] *shrugs* [Jun 22 21:39:56] pedro3005, stdlib.h is utility functions [Jun 22 21:40:24] ok [Jun 22 21:40:29] Perhaps named because it was more in general than the other parts of the standard library [Jun 22 21:40:34] Anyway [Jun 22 21:41:34] If a function happens to have the same name as a command, I suggest trying the 3rd part of manpages: man 3 [Jun 22 21:41:37] Okay? [Jun 22 21:41:51] okay [Jun 22 21:42:27] okay [Jun 22 21:42:33] I think that the final parts of this class will be taking questions, giving examples, and assigning, uh, assignments. [Jun 22 21:42:34] so now we're on our own [Jun 22 21:42:39] seidos, No. [Jun 22 21:42:39] here are the resources for learning [Jun 22 21:42:41] go read [Jun 22 21:42:50] :P [Jun 22 21:42:51] and implement some of these tools [Jun 22 21:43:02] seidos, Class isn't over yet. [Jun 22 21:43:05] :p [Jun 22 21:43:08] oh [Jun 22 21:43:20] There will be a few more [Jun 22 21:43:38] Asking you guys if you have questions or want to go over something again [Jun 22 21:43:49] Maybe a dip into 3rd party libraries [Jun 22 21:43:56] Assignments. [Jun 22 21:44:01] I'd think we'd benefit from exercising [Jun 22 21:44:11] Yes, thus "Assignments" :p [Jun 22 21:44:24] ...I should probably think of some beforehand * seidos [Jun 22 21:44:36] can't wait until he's graduated from "assignments" to "projects" [Jun 22 21:44:50] bgs100, maybe the UF beginner challenges? [Jun 22 21:44:50] BTW, about manpages [Jun 22 21:45:04] Yes! * bgs100 [Jun 22 21:45:10] gives pedro3005 star [Jun 22 21:45:12] In fact [Jun 22 21:45:20] I shall link to those next class [Jun 22 21:45:25] or this class [Jun 22 21:45:28] :p [Jun 22 21:45:41] seidos: it's coming up with stuff to write that's hard [Jun 22 21:46:02] hopefully I can do it [Jun 22 21:46:04] Snova, well, the hardest part is coming up with how to write it [Jun 22 21:46:10] You can ask me questions about doing things for those, sending me your code that doesn't work/works, etc. [Jun 22 21:46:18] And Snova too, methinks * bgs100 [Jun 22 21:46:39] volunteers Snova :p [Jun 22 21:46:43] "sending my your code that works" nothing odder than code that works when it shouldn't, eh? [Jun 22 21:46:50] Lol [Jun 22 21:46:59] I meant just to inspect a nice working product :P [Jun 22 21:47:10] I realized that shortly too late :p [Jun 22 21:47:11] But that too, I suppose [Jun 22 21:47:14] "You are not advanced enough to produce working code! *slaps with ruler*" [Jun 22 21:47:16] Ha * bgs100 [Jun 22 21:47:27] slaps pedro3005 with meterstick [Jun 22 21:47:45] This is a multi-nation/timezone ordeal! :p [Jun 22 21:47:59] bgs100, do we get bonuses for using 'goto' in every code we write? [Jun 22 21:48:07] pedro3005, Yes! [Jun 22 21:48:13] I will send you a nice present [Jun 22 21:48:19] A hungy raptor. [Jun 22 21:48:21] hungry* [Jun 22 21:49:02] Anyway [Jun 22 21:49:41] So yes, I suggest you try things on your own now, read about things, etc., and use the following lessons as a resource for help and additional learning. [Jun 22 21:50:05] Instead of my lesson plan, it will now be more of *your* lesson plan. [Jun 22 21:50:11] Okay? [Jun 22 21:50:15] okay * pedro3005 [Jun 22 21:50:20] shakes bgs100's hand * bgs100 [Jun 22 21:50:31] hands pedro3005 a diploma [Jun 22 21:50:44] :P * pedro3005 [Jun 22 21:50:50] frames and hangs it on a wall * bgs100 [Jun 22 21:51:17] says "Good work, pedro. Good work." [Jun 22 21:51:20] :P [Jun 22 21:51:25] Oh and seidos too :D [Jun 22 21:51:28] bgs100, okay, now Lisp [Jun 22 21:51:30] :P [Jun 22 21:51:32] YAY [Jun 22 21:51:51] ============ The History of Lisp ============ [Jun 22 21:51:53] :P [Jun 22 21:52:01] But anyway [Jun 22 21:52:13] pedro3005, seidos Do you currently have any questions vaguely related to C? :P [Jun 22 21:52:25] what language is firefox written in? [Jun 22 21:52:44] I asked in #firefox, but they told me to do a google search [Jun 22 21:52:49] http://en.wikipedia.org/wiki/Firefox [Jun 22 21:52:56] Written in C++, JavaScript,[3] CSS,[4][5] XUL, XBL [Jun 22 21:52:56] and the question is *vaguely* related to C [Jun 22 21:53:31] seidos, That's probably why they told you to search :P [Jun 22 21:53:32] bgs100, how different is C++ from C? [Jun 22 21:53:37] pedro3005, Hmm [Jun 22 21:53:39] Well [Jun 22 21:53:50] C++ has a lot of extra stuff [Jun 22 21:54:11] Classes, Templates, The STL, and such [Jun 22 21:54:27] They are close enough that you can use the C standard library in C++ [Jun 22 21:54:37] Lots of valid C code is also valid C++ [Jun 22 21:54:56] However, C++ does have a slightly stricter type system, so not all C code is valid C++. [Jun 22 21:55:35] g++ (C++ compiler) is part of gcc [Jun 22 21:55:48] alright [Jun 22 21:56:00] The STL really does add some nice classes [Jun 22 21:56:06] let me start the beginner's challenges then [Jun 22 21:56:11] Like strings, which you can add to each with +/+= [Jun 22 21:56:22] Er, a string class [Jun 22 21:56:26] pedro3005, Okay [Jun 22 21:56:37] pedro3005, Would you paste the link here? [Jun 22 21:56:44] http://ubuntuforums.org/showthread.php?p=5499486 [Jun 22 21:56:47] this has _some_ of them [Jun 22 21:56:49] but not all [Jun 22 21:57:00] the others you'll have to search for it because I am very lazy [Jun 22 21:57:03] Yeah, some more were later created [Jun 22 21:58:15] 2 looks interesting [Jun 22 21:58:53] Also [Jun 22 21:58:55] pedro3005, seidos [Jun 22 21:59:04] Some functions I suggest you look up: [Jun 22 21:59:06] fgets [Jun 22 21:59:10] ungetc [Jun 22 21:59:12] sscanf [Jun 22 21:59:14] sprintf [Jun 22 21:59:22] bgs100, oohhh yeah.. what about sockets? [Jun 22 21:59:42] *whistles* [Jun 22 22:00:04] thought you were getting away with it, huh! [Jun 22 22:00:09] was that a "walking away whistle", or a "woooow, that's big" whistle? [Jun 22 22:00:11] Those header files aren't part of the standard library [Jun 22 22:00:19] seidos, walking away [Jun 22 22:00:27] Those header files aren't part of the standard library, so I don't have to teach them! :P [Jun 22 22:00:41] But, honestly [Jun 22 22:00:51] you don't have to teach anything, for which I am grateful [Jun 22 22:01:04] er, that is, I am grateful that you are taking your time to teach us [Jun 22 22:01:08] I would suggest: [Jun 22 22:01:09] http://www.linuxhowtos.org/C_C++/socket.htm [Jun 22 22:01:12] seidos, Lol [Jun 22 22:01:22] You can come to me with any questions [Jun 22 22:01:38] There are man pages for the socket-related functions [Jun 22 22:01:44] as well. [Jun 22 22:01:49] oh good god [Jun 22 22:01:52] what did I get myself into? [Jun 22 22:02:00] holy f*** [Jun 22 22:02:26] ..... [Jun 22 22:02:30] it's like The client server model [Jun 22 22:02:45] LOL * seidos [Jun 22 22:03:05] cowers from *The client server model* [Jun 22 22:03:12] Well, admittedly, "C_C" was in the URL [Jun 22 22:03:22] the socket interface more or less comes down to; socket(), connect(), write() [Jun 22 22:03:24] okay, that's enough cowering, better start reading [Jun 22 22:03:27] ... who needs sockets anyway [Jun 22 22:03:36] :P [Jun 22 22:03:41] it's "complicated" to get around language limitations [Jun 22 22:05:51] bgs100, I keep forgetting things [Jun 22 22:05:56] :| [Jun 22 22:06:05] pedro3005, Quick, where are your car keys? [Jun 22 22:06:06] :p [Jun 22 22:07:43] nowhere [Jun 22 22:07:46] I don't have a car [Jun 22 22:08:20] you lost that too? [Jun 22 22:08:23] Well, good, at least you remember were those are. [Jun 22 22:08:26] where* [Jun 22 22:08:34] Hahaha [Jun 22 22:09:04] Snova, :P * bgs100 [Jun 22 22:09:44] gives Snova humo[u]r badge [Jun 22 22:09:54] er [Jun 22 22:09:58] yeah * bgs100 [Jun 22 22:10:07] has unilimited badge supply [Jun 22 22:10:11] unlimited* * bgs100 [Jun 22 22:10:24] gives self the keyboard failure badge [Jun 22 22:11:32] I forget things && I have a difficult time understanding things [Jun 22 22:11:45] *shrugs* [Jun 22 22:11:47] I'm doomed [Jun 22 22:11:54] bgs100, I don't know how to use scanf anymore [Jun 22 22:11:55] :P * bgs100 [Jun 22 22:11:55] teaches seidos how to fix that [Jun 22 22:11:59] Ohwait [Jun 22 22:12:03] That might not work [Jun 22 22:12:12] *dad da dum* [Jun 22 22:12:17] pedro3005, :| [Jun 22 22:12:22] pedro3005, Seriously? [Jun 22 22:12:26] bgs100, not really [Jun 22 22:12:33] Oh, good [Jun 22 22:12:35] to use it to get things like a name, we should use strings? [Jun 22 22:12:38] I think I still remember scanf [Jun 22 22:12:46] Oh [Jun 22 22:12:54] i remember we used ints to get characters anyway [Jun 22 22:12:54] now sscanf, different story [Jun 22 22:13:00] pedro3005, scanf isn't good for all input. [Jun 22 22:13:05] seidos, man sscanf [Jun 22 22:13:05] server.c doesn't really make sense [Jun 22 22:13:07] ah ha! [Jun 22 22:13:10] I'm going to compile it [Jun 22 22:13:22] right-o gotta' "man up" [Jun 22 22:13:31] xD [Jun 22 22:13:38] Was that pun intended? [Jun 22 22:13:45] indeed [Jun 22 22:14:34] pedro3005, e.g. the %s directive gets a string up to a whitespace. You can't easily use it to get, for instance, a line of text [Jun 22 22:14:37] okay, i'll use strings [Jun 22 22:14:41] Did you look up fgets? :P [Jun 22 22:14:48] no :p [Jun 22 22:14:54] Well do that :| * bgs100 [Jun 22 22:15:21] ssh's into pedro3005's computer and pipes man fgets | wall [Jun 22 22:15:37] hey why won't this work? [Jun 22 22:15:40] char *name[]; [Jun 22 22:15:41] What [Jun 22 22:15:45] ... [Jun 22 22:16:09] pedro3005, because if you don't give it a value at declaration you can't use [] [Jun 22 22:16:18] oh [Jun 22 22:16:26] Also [Jun 22 22:16:31] man, I bet the error catching code in firefox is awesome [Jun 22 22:16:34] Why do you want an array of char*'s? [Jun 22 22:16:43] I don't know [Jun 22 22:16:43] for the input at the URL box [Jun 22 22:16:55] pedro3005, :| [Jun 22 22:17:07] :P I need to grab a name as input [Jun 22 22:17:18] I'll just use getchar() [Jun 22 22:17:32] why use getchar() instead of scanf()? [Jun 22 22:18:43] damn, I wish I still had my getchar program [Jun 22 22:18:53] bgs100, I forgot how to use getchar.... :p [Jun 22 22:19:04] ....... [Jun 22 22:19:06] I think I have mine somewhere [Jun 22 22:19:10] *sigh* [Jun 22 22:19:13] I just don't know what I called it :o [Jun 22 22:19:17] pedro3005, What exactly are you trying to do? [Jun 22 22:19:20] how do you search inside a file? grep right? [Jun 22 22:19:26] bgs100, challenge 2 [Jun 22 22:19:29] seidos, mhm [Jun 22 22:20:36] pedro3005, scanf won't do well if you're trying to get a name that might have spaces... getchar() gets one individual char. [Jun 22 22:20:47] Just call it like so: getchar() [Jun 22 22:21:00] It will return EOF (-1) upon, well, EOF [Jun 22 22:21:15] pedro3005, Type this into your shell: [Jun 22 22:21:17] man fgets [Jun 22 22:21:19] Okay? [Jun 22 22:21:27] pedro3005, I found this: while ((c = getchar()) != EOF) { [Jun 22 22:21:27] putchar(toupper(c)); [Jun 22 22:21:27] if (c == '!') [Jun 22 22:21:27] printf("!!!"); [Jun 22 22:21:27] } [Jun 22 22:21:45] yeah but then I need to store this entire name [Jun 22 22:21:52] getchar() gets just one char [Jun 22 22:21:53] pedro3005, Yes... [Jun 22 22:21:58] If you wanted [Jun 22 22:22:07] You could build up into a char array. [Jun 22 22:22:13] getline [Jun 22 22:22:14] And add the '\0' yourself. [Jun 22 22:22:49] bgs100, btw the name can't have spaces so scanf() might be good.. but I suppose it needs to detect the presence of spaces and complains [Jun 22 22:22:58] complain* [Jun 22 22:23:07] Snova, Although it isn't standard :P [Jun 22 22:23:11] argh I just want raw_input() :( [Jun 22 22:23:20] pedro3005, man fgets [Jun 22 22:23:25] I did that [Jun 22 22:23:29] ...and? [Jun 22 22:23:46] pedro3005, are you working on the program challenges? [Jun 22 22:23:54] I'll try to do it with fgets() then [Jun 22 22:23:56] seidos, yes [Jun 22 22:23:58] Wait [Jun 22 22:24:04] pedro3005, The name can't have spaces? [Jun 22 22:24:05] I should do the same [Jun 22 22:24:10] Go ahead and try scanf. [Jun 22 22:24:20] See if it works. [Jun 22 22:24:35] so wait, a quick reminder.. should I do like [Jun 22 22:24:42] int name; [Jun 22 22:24:49] ... [Jun 22 22:24:51] No. [Jun 22 22:24:52] scanf("%d",&name); [Jun 22 22:25:07] Unless someone's name is "57"... [Jun 22 22:25:19] :P [Jun 22 22:25:52] waait [Jun 22 22:26:04] pedro3005, Where in the challenge does it say the name can't have spaces? [Jun 22 22:26:29] oh wait [Jun 22 22:26:35] it can't _begin_ with spaces [Jun 22 22:26:37] failure [Jun 22 22:27:03] .... [Jun 22 22:27:06] Indeed. [Jun 22 22:27:28] and I thought this was hard on Python some months ago [Jun 22 22:28:10] pedro3005, Do something like: [Jun 22 22:28:14] char input[21]; [Jun 22 22:28:25] fgets(input, 20, stdin); [Jun 22 22:28:46] bgs100, but then the input is limited :| [Jun 22 22:28:53] And I would uggest seeing if the last non '\0' character is a newline and if so replace it with '\0' [Jun 22 22:29:13] pedro3005, That's okay. [Jun 22 22:29:31] "To make this simpler, I will not enter a string bigger than 20 characters for valid data, but larger strings shouldn't cause problems. Truncate them.)" [Jun 22 22:29:50] is -- an operator? [Jun 22 22:29:57] Yes [Jun 22 22:29:59] don't you mean fgets(input, 21, stdin) ? [Jun 22 22:30:02] The opposite of ++ [Jun 22 22:30:06] pedro3005, No. [Jun 22 22:30:16] Errr [Jun 22 22:30:18] Yes :P [Jun 22 22:30:20] fgets() reads in at most one less than size characters [Jun 22 22:30:25] yeah [Jun 22 22:30:28] bgs100, please do man fgets [Jun 22 22:30:29] :P * bgs100 [Jun 22 22:30:31] gives pedro3005 the correct badge [Jun 22 22:30:37] pedro3005, Oh Har Har Har * bgs100 [Jun 22 22:30:50] whacks pedro3005 with meterstick [Jun 22 22:31:01] er * bgs100 [Jun 22 22:31:05] notices time [Jun 22 22:31:09] CLASS DISMISSED [Jun 22 22:31:10] bgs100, but wouldn't there be a way not to limit the input? [Jun 22 22:31:15] pedro3005, Yes [Jun 22 22:31:17] In fact [Jun 22 22:31:28] pedro3005, I was annoyed by exactly the same thing before. [Jun 22 22:31:38] How hard it was to get not-so-limited input [Jun 22 22:31:47] I ended up just writing a function :P [Jun 22 22:32:38] int fuck_scanf() { [Jun 22 22:33:00] because that's what I feel like [Jun 22 22:33:08] ... [Jun 22 22:33:26] I wrote this a while back, it may not be totally correct (pings Snova), but: [Jun 22 22:34:07] hey I could actually use goto in this [Jun 22 22:34:50] http://paste.pocoo.org/show/228775/ [Jun 22 22:35:48] ugh [Jun 22 22:36:01] eh? [Jun 22 22:36:04] getline() should be used similarly to raw_input() (without optional text to print) [Jun 22 22:36:24] Snova, Mind checking code I wrote a long time ago? :P [Jun 22 22:36:35] brb [Jun 22 22:38:37] interesting [Jun 22 22:39:23] it's fairly dense, but seems to work right [Jun 22 22:39:32] yaaay [Jun 22 22:39:34] barring tricksy little off-by-one errors [Jun 22 22:43:11] gah [Jun 22 22:43:16] } while ((isspace(char[0])) || !(char[0])); [Jun 22 22:43:16] pedro3005, ? [Jun 22 22:43:19] er [Jun 22 22:43:19] why doesn [Jun 22 22:43:25] I mean [Jun 22 22:43:25] it work [Jun 22 22:43:32] I'll be taking questions next class :P [Jun 22 22:43:42] Snova? :p [Jun 22 22:43:50] Uh [Jun 22 22:43:54] I was kidding :| [Jun 22 22:44:02] oh [Jun 22 22:44:07] *sighs* [Jun 22 22:44:25] pedro3005, What is that } about? [Jun 22 22:44:29] do while [Jun 22 22:44:44] Could I see the do? :P [Jun 22 22:45:22] do { [Jun 22 22:45:22] puts("Enter your forum name."); [Jun 22 22:45:22] fgets(input, 21, stdin); [Jun 22 22:45:22] } [Jun 22 22:45:32] ... [Jun 22 22:45:34] what is char? [Jun 22 22:45:49] hm? [Jun 22 22:46:04] You take it into input, then use "char" [Jun 22 22:46:12] ... [Jun 22 22:46:50] bgs100, oh failure [Jun 22 22:46:53] my god [Jun 22 22:46:56] how did I.. [Jun 22 22:46:58] *facepalm* [Jun 22 22:47:08] is there a way to put a text file into the paste buffer via the command line? [Jun 22 22:47:16] like sample.txt > paste [Jun 22 22:47:18] or something? [Jun 22 22:47:20] Paste buffer? [Jun 22 22:47:29] copy buffer? [Jun 22 22:47:34] frame buffer? [Jun 22 22:47:38] ... [Jun 22 22:47:39] bgs100, it works bitches!!! [Jun 22 22:47:41] :P [Jun 22 22:47:45] I'm not sure what it's called * bgs100 [Jun 22 22:47:48] slaps pedro3005 [Jun 22 22:48:07] pedro3005, Also, I am not plural :P [Jun 22 22:48:17] why doesn't this loop go negative for(i=99; i>=0; i--)? [Jun 22 22:48:18] I AM THE COLLECTIVE [Jun 22 22:48:26] I was referring to the bitches in general [Jun 22 22:48:31] oh [Jun 22 22:48:36] I AM THE COLLECTIVE! [Jun 22 22:48:38] :P [Jun 22 22:48:51] seidos, Errr [Jun 22 22:48:54] bgs100, I excluded you out of niceness, be grateful [Jun 22 22:48:59] Are you sure it isn't? [Jun 22 22:49:11] pedro3005, *rolls eyes* [Jun 22 22:49:42] bgs100, you'll have to explain your code next class :p [Jun 22 22:49:49] :| [Jun 22 22:49:53] ...okay :P * bgs100 [Jun 22 22:50:07] goes off to do other computer stuff [Jun 22 22:50:30] pedro3005, can you see why my loop doesn't go negative so it will stop? [Jun 22 22:50:45] if I set it >=1 it stops, but >=0 it just loops forever [Jun 22 22:51:04] hmmm [Jun 22 22:52:57] here it works [Jun 22 22:53:07] int main() { [Jun 22 22:53:07] int i; [Jun 22 22:53:08] for (i=10; i >= 0; i--) [Jun 22 22:53:08] puts("Hello."); [Jun 22 22:53:08] return 0; [Jun 22 22:53:08] } [Jun 22 22:53:25] it prints 10 times [Jun 22 22:53:33] no more [Jun 22 22:53:35] no less [Jun 22 22:53:38] :p [Jun 22 22:54:47] hmm [Jun 22 22:54:54] seidos, is i a normal int? [Jun 22 22:54:59] yeah [Jun 22 22:55:01] int i; [Jun 22 22:55:04] hmm [Jun 22 22:55:06] long int? [Jun 22 22:55:10] what are you doing in the loop? [Jun 22 22:55:53] printf's [Jun 22 22:56:10] Paste? [Jun 22 22:56:44] http://paste.ubuntu.com/453703/ [Jun 22 22:56:54] seidos, ##philosophy gets quite... interesting [Jun 22 22:56:56] to say the least [Jun 22 22:57:06] someone pm'ed earlier [Jun 22 22:57:19] was trying to say that suffering is what humans crave [Jun 22 22:57:30] because it gives them/us "individuality" [Jun 22 22:57:37] :| [Jun 22 22:57:37] he said happiness was overrated [Jun 22 22:57:43] Uhhh [Jun 22 22:57:45] seidos, [Jun 22 22:57:46] I said individuality is overrated * seidos [Jun 22 22:57:51] hides [Jun 22 22:57:55] well that's okay [Jun 22 22:58:01] I think you want == in those if's [Jun 22 22:58:06] not ='s [Jun 22 22:58:10] Those assign i... [Jun 22 22:58:10] i need to cut down on my masturbation habits [Jun 22 22:58:14] however.. [Jun 22 22:58:15] :P [Jun 22 22:58:21] Not check if it is a value.. [Jun 22 22:58:31] yes. that was an epic fail. [Jun 22 22:58:49] thank you [Jun 22 22:58:53] I do that to damn much [Jun 22 22:59:00] s/to/too [Jun 22 22:59:07] :p [Jun 22 22:59:51] no wonder I got a warning from the compiler :/ [Jun 22 23:00:03] man [Jun 22 23:00:25] hindsight is miraculous [Jun 22 23:00:28] seidos, Pay attention to those [Jun 22 23:00:51] When you have a problem, paste the warnings (if there's only a few on IRC) [Jun 22 23:00:55] I'll do my best [Jun 22 23:01:55] :) [Jun 22 23:12:00] I don't get how can I take chars using scanf [Jun 22 23:12:10] "%d" is for ints [Jun 22 23:12:18] but I don't know what to use for chars [Jun 22 23:12:25] man scanf doesn't seem to say [Jun 22 23:12:39] %c? [Jun 22 23:13:27] I don't know, I still get some warnings [Jun 22 23:13:40] me neither [Jun 22 23:13:50] but I think that fixed some of them maybe [Jun 22 23:16:18] I like this warning "comparison with string literal results in unspecified behavior [Jun 22 23:16:19] " [Jun 22 23:16:26] I mean, what is "unspecified behavior"? [Jun 22 23:16:29] let's find out! * seidos [Jun 22 23:16:33] executes binary [Jun 22 23:17:01] it wouldn't execute :( [Jun 22 23:18:07] compiling to a text file using > doesn't work to grab the warnings into a file [Jun 22 23:18:40] ah, wasn't seeing an error * seidos [Jun 22 23:18:56] facepalms himself *thwap* [Jun 22 23:19:07] stdio.c? no! stdio.h * seidos [Jun 22 23:19:19] bangs his head and chants "stupid, stupid, stupid" [Jun 23 00:51:52] Night }}}