What is sprintf?

Asked 1 years ago, Updated 1 years ago, 45 views

How does sprintf work in the following programs?

 if(p>=10000){
    US>sprintf(str, "D:\\○○Research_Production Information Special Experiment_Nakayama_Succession\\System\\Final\\OpenCV-Sample001\\Lecture Image\\cap%05d.bmp",
} else {
    sprintf(str, "D:\\○○ Laboratory_Production Information Special Experiment_Nakayama_Succession\\System\\Final\\OpenCV-Sample001\\Lecture Image\\cap%04d.bmp",p);
}

c++ c

2022-09-30 21:35

2 Answers

( and )
sprintf in is a function that outputs a formatted string to an array of char.
https://msdn.microsoft.com/ja-jp/library/ybk95axf.aspx (mechanical translation)
https://linuxjm.osdn.jp/html/LDP_man-pages/man3/printf.3.html
(This should be easier to read)

The str in the presentation code should be an array of char defined like charstr[_MAX_PATH];.
sprintf format the string (in this example, %d is stored in multiple characters where %d is used to estimate and record teacher behavior during the lecture.
Note that backslashes in source code are escaped during compilation.


2022-09-30 21:35

774RR has already answered in detail, but for beginners,

"Create a new string by combining values and strings stored in variables"

It is often used for this purpose.


2022-09-30 21:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.