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. zero termination for BYTE?

zero termination for BYTE?

Scheduled Pinned Locked Moved C / C++ / MFC
questioniostutorial
4 Posts 3 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
    Souldrift
    wrote on last edited by
    #1

    Hi there, this might be a slightly stupid question, but when I write a single BYTE into a file (using ofstream), does it need to be null-terminated? Do BYTE streams generally have to be? Example code:

    char* buf = new char[128];
    sprintf_s( buf, 128, "TestOutput/RTPEngineBin%04d.out", m_iFileCount );

    m_oStream3.open(buf, ios::out|ios::binary);

    if( !m_oStream3 )
    {
    // ...
    }

    for( int i = 0; i < 12; i++ )
    {
    m_oStream3 << header[i];
    }

    m_oStream3 << data; // data == 1 BYTE

    m_oStream3.flush();
    m_oStream3.close();

    delete [] buf;

    This is a small rtp package. Header has 12 bytes and the payload is just a single byte. Cheers Souldrift

    S L S 3 Replies Last reply
    0
    • S Souldrift

      Hi there, this might be a slightly stupid question, but when I write a single BYTE into a file (using ofstream), does it need to be null-terminated? Do BYTE streams generally have to be? Example code:

      char* buf = new char[128];
      sprintf_s( buf, 128, "TestOutput/RTPEngineBin%04d.out", m_iFileCount );

      m_oStream3.open(buf, ios::out|ios::binary);

      if( !m_oStream3 )
      {
      // ...
      }

      for( int i = 0; i < 12; i++ )
      {
      m_oStream3 << header[i];
      }

      m_oStream3 << data; // data == 1 BYTE

      m_oStream3.flush();
      m_oStream3.close();

      delete [] buf;

      This is a small rtp package. Header has 12 bytes and the payload is just a single byte. Cheers Souldrift

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Souldrift wrote:

      when I write a single BYTE into a file (using ofstream), does it need to be null-terminated? Do BYTE streams generally have to be?

      No to both. NULL-termination is merely a C convention for the representation of strings.

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      1 Reply Last reply
      0
      • S Souldrift

        Hi there, this might be a slightly stupid question, but when I write a single BYTE into a file (using ofstream), does it need to be null-terminated? Do BYTE streams generally have to be? Example code:

        char* buf = new char[128];
        sprintf_s( buf, 128, "TestOutput/RTPEngineBin%04d.out", m_iFileCount );

        m_oStream3.open(buf, ios::out|ios::binary);

        if( !m_oStream3 )
        {
        // ...
        }

        for( int i = 0; i < 12; i++ )
        {
        m_oStream3 << header[i];
        }

        m_oStream3 << data; // data == 1 BYTE

        m_oStream3.flush();
        m_oStream3.close();

        delete [] buf;

        This is a small rtp package. Header has 12 bytes and the payload is just a single byte. Cheers Souldrift

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Souldrift wrote:

        Do BYTE streams generally have to be?

        Short answer is no. Since it is your application it is your decision. The only thing to bear in mind is that the program that reads the file needs to understand, and use, the same format rules as the program that writes it.

        1 Reply Last reply
        0
        • S Souldrift

          Hi there, this might be a slightly stupid question, but when I write a single BYTE into a file (using ofstream), does it need to be null-terminated? Do BYTE streams generally have to be? Example code:

          char* buf = new char[128];
          sprintf_s( buf, 128, "TestOutput/RTPEngineBin%04d.out", m_iFileCount );

          m_oStream3.open(buf, ios::out|ios::binary);

          if( !m_oStream3 )
          {
          // ...
          }

          for( int i = 0; i < 12; i++ )
          {
          m_oStream3 << header[i];
          }

          m_oStream3 << data; // data == 1 BYTE

          m_oStream3.flush();
          m_oStream3.close();

          delete [] buf;

          This is a small rtp package. Header has 12 bytes and the payload is just a single byte. Cheers Souldrift

          S Offline
          S Offline
          Souldrift
          wrote on last edited by
          #4

          Thanks. That´s what I thought. Only someone asked me a question about the topic and got me quite confused. Souldrift

          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