Hello
Can some one please explain what this statement is
I am very new to C++ and VC++ statement
sprintf(DirString,"%s/cl_log.csv",DirName);
I could not understand what second argument
Thanks in advance,
Durga
Hello
Can some one please explain what this statement is
I am very new to C++ and VC++ statement
sprintf(DirString,"%s/cl_log.csv",DirName);
I could not understand what second argument
Thanks in advance,
Durga
If you're using C++, sprintf is not the right tool. Now here's the answer.
The second argument is a format string. The sprintf subroutine copies the format string to the bytes of memory pointed to by DirString.
The thing is, it replaces "%s" with the contents of the string DirName. The percent sign is given special interpretation, and %s makes the subroutine insert the characters of a string.
Other characters can be used behind the percent sign for different meaning. For example, %d will draw the decimal representation of an integer. E.g.
sprintf(DirString, "%s/cl_log.csv %d", DirName, 478);
The first insertion code, %s, corresponds to DirName, and the second, %d, corresponds to 478. The character array pointed to by DirString will be just like it was in the code you provided, except with " 478" on the end.
You can see a ludicrously (and usefully) in-depth description of all the printf and sprintf options at http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.12.html#printf, but it does not have any examples.
what is the use of CL_log.csv file
If you're using C++, sprintf is not the right tool. Now here's the answer.
The second argument is a format string. The sprintf subroutine copies the format string to the bytes of memory pointed to by DirString.
The thing is, it replaces "%s" with the contents of the string DirName. The percent sign is given special interpretation, and %s makes the subroutine insert the characters of a string.
Other characters can be used behind the percent sign for different meaning. For example, %d will draw the decimal representation of an integer. E.g.
sprintf(DirString, "%s/cl_log.csv %d", DirName, 478);
The first insertion code, %s, corresponds to DirName, and the second, %d, corresponds to 478. The character array pointed to by DirString will be just like it was in the code you provided, except with " 478" on the end.
You can see a ludicrously (and usefully) in-depth description of all the printf and sprintf options at http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.12.html#printf, but it does not have any examples.
Basically it allows you to create a string with known values and populated values.. perhaps an example like this.
char name[] = "coolgirl";
int num = 10;
sprintf( finalDest, "%s wants to go out %d times today", name, num );
will end up copying "coolgirl wants to go out 10 times today" into finalDest;
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.