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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Easy question:

Easy question:

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 4 Posters 0 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.
  • S Offline
    S Offline
    Sunnygirl
    wrote on last edited by
    #1

    hello @all, i have: char r1[1000]; how can i delete the char r1??? thanks you sunny

    C G 2 Replies Last reply
    0
    • S Sunnygirl

      hello @all, i have: char r1[1000]; how can i delete the char r1??? thanks you sunny

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      you can't "delete" something that you didn't create with "new". -c


      WWT2D?

      Fractals

      1 Reply Last reply
      0
      • S Sunnygirl

        hello @all, i have: char r1[1000]; how can i delete the char r1??? thanks you sunny

        G Offline
        G Offline
        georgiek50
        wrote on last edited by
        #3

        If you mean clearing out the array do this: r1[0] = '\0'; (All clear!)

        H 1 Reply Last reply
        0
        • G georgiek50

          If you mean clearing out the array do this: r1[0] = '\0'; (All clear!)

          H Offline
          H Offline
          Harold Bamford
          wrote on last edited by
          #4

          georgiek50 wrote: If you mean clearing out the array do this: r1[0] = '\0'; (All clear!) This assumes you are using r1 as a character string rather than an array of bytes. If you want to "clear out" an array, try:

          memset(r1,0,1000);  // where 1000 is the number of bytes in r1
          
          G 1 Reply Last reply
          0
          • H Harold Bamford

            georgiek50 wrote: If you mean clearing out the array do this: r1[0] = '\0'; (All clear!) This assumes you are using r1 as a character string rather than an array of bytes. If you want to "clear out" an array, try:

            memset(r1,0,1000);  // where 1000 is the number of bytes in r1
            
            G Offline
            G Offline
            georgiek50
            wrote on last edited by
            #5

            Even though it is an array of byte wouldn't \0 take care of everything? which brings me to ask another question. If I declared an array of bytes say array[100] but then only needed to fill the first fifty. Do I need a NULL character like in a string? If yes how would I set it. If no, why not?

            H 1 Reply Last reply
            0
            • G georgiek50

              Even though it is an array of byte wouldn't \0 take care of everything? which brings me to ask another question. If I declared an array of bytes say array[100] but then only needed to fill the first fifty. Do I need a NULL character like in a string? If yes how would I set it. If no, why not?

              H Offline
              H Offline
              Harold Bamford
              wrote on last edited by
              #6

              georgiek50 wrote: Even though it is an array of byte wouldn't \0 take care of everything? which brings me to ask another question. If I declared an array of bytes say array[100] but then only needed to fill the first fifty. Do I need a NULL character like in a string? If yes how would I set it. If no, why not? I didn't make myself clear. If you are using the array of bytes as a null-terminated cstring: strcpy(r1,"This is a string"); Then terminating at the "zero'th" position will clear out the string. For example, if you said:

              strcpy(r1,"0123456789 This is a string");
              r1[15] = 0;
              printf("%s\n", r1);
              

              The output would be "0123456789 This" If you then dumped the first 20 bytes of r1:

              for(int i = 0; i < 20; i++)
              {
                 printf("0x%02X ", r1[i]);
              }
              

              You would get something like: 0x30 0x31 0x32 ... 0x39 0x20 0x54 0x68 0x69 0x73 **0x00** 0x69 0x73 ... That's the convention for null-terminated cstrings (not to be confused with CString); a 0 terminates the string. If it is just an array of bytes, then 0 is just another value.

              G 1 Reply Last reply
              0
              • H Harold Bamford

                georgiek50 wrote: Even though it is an array of byte wouldn't \0 take care of everything? which brings me to ask another question. If I declared an array of bytes say array[100] but then only needed to fill the first fifty. Do I need a NULL character like in a string? If yes how would I set it. If no, why not? I didn't make myself clear. If you are using the array of bytes as a null-terminated cstring: strcpy(r1,"This is a string"); Then terminating at the "zero'th" position will clear out the string. For example, if you said:

                strcpy(r1,"0123456789 This is a string");
                r1[15] = 0;
                printf("%s\n", r1);
                

                The output would be "0123456789 This" If you then dumped the first 20 bytes of r1:

                for(int i = 0; i < 20; i++)
                {
                   printf("0x%02X ", r1[i]);
                }
                

                You would get something like: 0x30 0x31 0x32 ... 0x39 0x20 0x54 0x68 0x69 0x73 **0x00** 0x69 0x73 ... That's the convention for null-terminated cstrings (not to be confused with CString); a 0 terminates the string. If it is just an array of bytes, then 0 is just another value.

                G Offline
                G Offline
                georgiek50
                wrote on last edited by
                #7

                Ok, I see what you're saying now.

                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