Assignment [modified]
-
Spent about 45 min trying to figure out why title was lost after returning at the end of the function:-O.
DoSomething(Text *text_store, int seven) { char *text; text = (char*) malloc(sizeof(char) * seven); //more code text_store.title = text; free(text); }
-- modified at 15:05 Monday 5th November, 2007 And yes text_store.title is a pointerthis thing looks like it was written by an epileptic ferret Dave Kreskowiak
-
Spent about 45 min trying to figure out why title was lost after returning at the end of the function:-O.
DoSomething(Text *text_store, int seven) { char *text; text = (char*) malloc(sizeof(char) * seven); //more code text_store.title = text; free(text); }
-- modified at 15:05 Monday 5th November, 2007 And yes text_store.title is a pointerthis thing looks like it was written by an epileptic ferret Dave Kreskowiak
Is your post missing some content? Peace!
-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
Is your post missing some content? Peace!
-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFilesI think thats what the // more code is for :)
xacc.ide
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach." -
Spent about 45 min trying to figure out why title was lost after returning at the end of the function:-O.
DoSomething(Text *text_store, int seven) { char *text; text = (char*) malloc(sizeof(char) * seven); //more code text_store.title = text; free(text); }
-- modified at 15:05 Monday 5th November, 2007 And yes text_store.title is a pointerthis thing looks like it was written by an epileptic ferret Dave Kreskowiak
Well if the type of 'text_store.title' is pointer, then you are freeing the memory that it points to. That will usually create havoc. :)
Chris Meech I am Canadian. [heard in a local bar] Donate to help Conquer Cancer[^]
-
Is your post missing some content? Peace!
-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFilesThe post originally showed no code, then was modified (after my post). Peace!
-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
Spent about 45 min trying to figure out why title was lost after returning at the end of the function:-O.
DoSomething(Text *text_store, int seven) { char *text; text = (char*) malloc(sizeof(char) * seven); //more code text_store.title = text; free(text); }
-- modified at 15:05 Monday 5th November, 2007 And yes text_store.title is a pointerthis thing looks like it was written by an epileptic ferret Dave Kreskowiak
-
Spent about 45 min trying to figure out why title was lost after returning at the end of the function:-O.
DoSomething(Text *text_store, int seven) { char *text; text = (char*) malloc(sizeof(char) * seven); //more code text_store.title = text; free(text); }
-- modified at 15:05 Monday 5th November, 2007 And yes text_store.title is a pointerthis thing looks like it was written by an epileptic ferret Dave Kreskowiak
Uhh....loooks like you've forgotten 1 extra for NUL terminated char... text = (char*)malloc(sizeof(char) * (seven + 1)); And also...check for NULL if this fails...my c skills are a bit rusty so excuse if I trip up, from what I can remember this nice terse statement which was favourite of mine.. if (!(text = (char*)malloc(sizeof(char) * (seven+1)))){ ...mem is gud... }else{ ...phffft... } this is a nice lil exercise since I used to program in C professionally, then switched over to C# cos the skillset was dwindling in the IT sector here in Ireland... not sure why you'd free the pointer though...I think that you'll have garbage in text_store.title...I could be way off here on this... Take care, Tom
#define STOOPID #if STOOPID Console.WriteLine("I'm stoopid!"); #endif