将不满_numBits位的字符串用0补全

来源:互联网 发布:js disabled 编辑:程序博客网 时间:2024/05/17 05:59

以下是C实现的代码:

 

void FillStrWithZero(char* _strIn, char* _strOut, int _numBits)  

{

       if (_numBits <= strlen(_strIn))

       {

              return;

       }

       if (strlen(_strIn) < _numBits)

       {

              int loop = 0;

              while (loop < _numBits - strlen(_strIn))

              {

                     _strOut[loop] = '0';

                     loop++;

              }

 

              strcat(_strOut, _strIn);

       }

}

原创粉丝点击