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. Visual Studio
  4. in vc++, Debug assertion failed Expression: length < sizeInTChars

in vc++, Debug assertion failed Expression: length < sizeInTChars

Scheduled Pinned Locked Moved Visual Studio
c++debugginghelptutorial
4 Posts 2 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.
  • A Offline
    A Offline
    anne_rose
    wrote on last edited by
    #1

    Hi, Header.h --------

    using namespace std;

    class defaultlog
    {
    public:
    static unsigned int& CmdNumber()
    {
    static unsigned int cmd_Number(0);
    return cmdNumbers;
    }
    static unsigned int& ErrorCount()
    {
    static unsigned int err_count(0);
    return errcounts;
    }
    };

    and my main.cpp

     char sErrNumb[7];
     char  scmdNumb[5];
    
    
    void ClearLog()
    {
        _itoa_s(logger::CmdNumber()++,scmdNumb,10);	
        _itoa_s(logger::ErrCount(),sErrNumb,10);
        fprintf(fileName," %s",sErrNumb);
    

    } when the control reaches the first _itoa_s I get the DEBUG ASSERTION FAILED (refer subject) How to solve this problem. I pass the scmdNumb to a file using fprintf

    L 1 Reply Last reply
    0
    • A anne_rose

      Hi, Header.h --------

      using namespace std;

      class defaultlog
      {
      public:
      static unsigned int& CmdNumber()
      {
      static unsigned int cmd_Number(0);
      return cmdNumbers;
      }
      static unsigned int& ErrorCount()
      {
      static unsigned int err_count(0);
      return errcounts;
      }
      };

      and my main.cpp

       char sErrNumb[7];
       char  scmdNumb[5];
      
      
      void ClearLog()
      {
          _itoa_s(logger::CmdNumber()++,scmdNumb,10);	
          _itoa_s(logger::ErrCount(),sErrNumb,10);
          fprintf(fileName," %s",sErrNumb);
      

      } when the control reaches the first _itoa_s I get the DEBUG ASSERTION FAILED (refer subject) How to solve this problem. I pass the scmdNumb to a file using fprintf

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

      That code will not even compile. Also, this is not a Visual Studio issue, please use the C++ forum.

      Veni, vidi, abiit domum

      A 1 Reply Last reply
      0
      • L Lost User

        That code will not even compile. Also, this is not a Visual Studio issue, please use the C++ forum.

        Veni, vidi, abiit domum

        A Offline
        A Offline
        anne_rose
        wrote on last edited by
        #3

        Thanks Richard, but this code is in VC++ and it did work.... The class "defaultlog" was executed successfully in a subfunction defined under test.cpp Then once the control branches to main.cpp, i get this error.

        L 1 Reply Last reply
        0
        • A anne_rose

          Thanks Richard, but this code is in VC++ and it did work.... The class "defaultlog" was executed successfully in a subfunction defined under test.cpp Then once the control branches to main.cpp, i get this error.

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

          Well, I am sorry but the code you have shown does not compile, so it cannot be the code you have in your project. And there is no such language as VC++, it is C++.

          Veni, vidi, abiit domum

          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