Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Assignment [modified]

Assignment [modified]

Scheduled Pinned Locked Moved The Weird and The Wonderful
7 Posts 6 Posters 31 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jim Warburton
    wrote on last edited by
    #1

    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 pointer

    this thing looks like it was written by an epileptic ferret Dave Kreskowiak

    J C K T 4 Replies Last reply
    0
    • J Jim Warburton

      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 pointer

      this thing looks like it was written by an epileptic ferret Dave Kreskowiak

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #2

      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

      L J 2 Replies Last reply
      0
      • J James R Twine

        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

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        I 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."

        1 Reply Last reply
        0
        • J Jim Warburton

          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 pointer

          this thing looks like it was written by an epileptic ferret Dave Kreskowiak

          C Offline
          C Offline
          Chris Meech
          wrote on last edited by
          #4

          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[^]

          1 Reply Last reply
          0
          • J James R Twine

            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

            J Offline
            J Offline
            James R Twine
            wrote on last edited by
            #5

            The 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

            1 Reply Last reply
            0
            • J Jim Warburton

              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 pointer

              this thing looks like it was written by an epileptic ferret Dave Kreskowiak

              K Offline
              K Offline
              KarstenK
              wrote on last edited by
              #6

              Make title a CString and it should work fine.:-O

              Greetings from Germany

              1 Reply Last reply
              0
              • J Jim Warburton

                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 pointer

                this thing looks like it was written by an epileptic ferret Dave Kreskowiak

                T Offline
                T Offline
                Tomas Brennan
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups