At 03:13 PM 3/11/98 -0600, you wrote: >char *one_of_my_functions(int nothing) { > char mybuf[SIZE]; char *mybuf; > > switch(nothing) { > > case 1: > sprintf(mybuf,"NOTHING IS ONE"); mybuf = "NOTHING IS ONE"; > break; > case 2: > sprintf(mybuf,"NOTHING IS TWO"); mybuf = "NOTHING IS TWO"; > break; > default: > sprintf(mybuf,"DieDieDie!!!"); mybuf = "DieDieDie!!!"; break; // good C coding skills tell you to always put a break after default: > } > > return strdup(mybuf); return (mybuf); >} > > OR is there something prettier that I'm overlooking... If what I typed is correct, it should work, because I'm assigning the data ("NOTHING IS TWO", et al.)to a pointer (mybuf). and the data is stored in memory like that, so there should be no need for str_dup, especially if you are just going to forget to free() it anyway :-P If i'm not correct in my assumption, please feel free to correct me. Keep in mind that flames are not necessary. Code On Akuma the Raging Coder +------------------------------------------------------------+ | "The poets talk about love, but what I talk about is DOOM, | | because in the end, DOOM is all that counts." - | | Alex Machine/George Stark/Stephen King, The Dark Half | | "Nothing is IMPOSSIBLE, Just IMPROBABLE" | | "Easier Said Than Done, But Better Done Than Said..." | +------------------------------------------------------------+ +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST