sprintf_s function usage

Reprinted: https: //blog.csdn.net/lile777/article/details/41819449

sprintf_s function usage

Function: the output data is formatted into a string

Function prototype :

  1.  
       int sprintf_s(
  2.  
     
  3.  
      char *buffer,
  4.  
     
  5.  
      size_t sizeOfBuffer,
  6.  
     
  7.  
      const char *format [,
  8.  
     
  9.  
      argument] ...
  10.  
     
  11.  
      );

You need to include the header file: stdio.h

note:

         sprintf_s () is sprintf () version of security to avoid buffer length specified by sprintf () overflow risks

Program example:

  1.  
    filename char [ 1024]; // need to pre-allocate buffers
  2.  
     
  3.  
    char path1[128] = "D:\\Program\\Tesseract-OCR\\tesseract.exe";
  4.  
    char path2[128] = "D:\\Program\\Tesseract-OCR\\";
  5.  
    char path3[128] = "D:\\Program\\Tesseract-OCR\\txt";
  6.  
    char path4[128] = "-l chi_sim";
  7.  
     
  8.  
    sprintf_s(filename, sizeof( filename ), "%s %s %s %s", path1,filepath,path3,path4);
  9.  
     
  10.  
    system(filename);

 

>>> http://blog.csdn.net/tigernana/article/details/6916491

related functions:

         snprintf()

Guess you like

Origin www.cnblogs.com/MCSFX/p/12654779.html