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. General Programming
  3. C / C++ / MFC
  4. Make buffer zero?

Make buffer zero?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 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.
  • K Offline
    K Offline
    Kiran Pinjala
    wrote on last edited by
    #1

    I have char buf[10]; First i declared it as char buf[10] = {0}; In the middle of my code after using that buf, I again want to make buffer to zero. How to do that?

    KIRAN PINJARLA

    P Z 2 Replies Last reply
    0
    • K Kiran Pinjala

      I have char buf[10]; First i declared it as char buf[10] = {0}; In the middle of my code after using that buf, I again want to make buffer to zero. How to do that?

      KIRAN PINJARLA

      P Offline
      P Offline
      Parthi_Appu
      wrote on last edited by
      #2

      Use ZeroMemory(..) as ZeroMemory(buf, sizeof(buf));

      Do your Duty and Don't expect the Result

      1 Reply Last reply
      0
      • K Kiran Pinjala

        I have char buf[10]; First i declared it as char buf[10] = {0}; In the middle of my code after using that buf, I again want to make buffer to zero. How to do that?

        KIRAN PINJARLA

        Z Offline
        Z Offline
        Zac Howland
        wrote on last edited by
        #3

        For platform independent code: memset(buf, 0, 10);

        If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

        V 1 Reply Last reply
        0
        • Z Zac Howland

          For platform independent code: memset(buf, 0, 10);

          If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

          V Offline
          V Offline
          Vipin Aravind
          wrote on last edited by
          #4

          better use sizeof(buf) instead of 10, it will save you some headache if someone changes the "char buf[10]" in future.

          Click here for Vipin's Blog

          Z 1 Reply Last reply
          0
          • V Vipin Aravind

            better use sizeof(buf) instead of 10, it will save you some headache if someone changes the "char buf[10]" in future.

            Click here for Vipin's Blog

            Z Offline
            Z Offline
            Zac Howland
            wrote on last edited by
            #5

            I was using it to illustrate the call. sizeof will work on items declared on the stack, but not the heap. So, code like char* pChar = new char[30]; cout << sizeof(pChar) << endl; will output 4 instead of 30.

            If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

            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