|
| |||||||||
| Tags: c language, library functions, printf, vsprintf |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Implementation of vsprintf() : C
Hello, I am student of the Msc(Computer Science). I have the knowledge of the C language. Periodically, I must have to submit the assignments suggested by the professor. I know about the printf() function. But I did not know about the vsprintf() function. So, I want to know what is vsprintf() function, How can they be used in the program, and what is the diference between the vsprintf() and printf() functions. Can anyone know about the vsprintf() function. |
|
#2
| ||||
| ||||
| Re: Implementation of vsprintf() : C
Using argument list the vsprintf() function sends formatted output to the string. I think It is good enough for you to know about the vsprintf() function. The following is the syntax of the vsprintf() function : #include <stdarg.h> #include <stdio.h> int vsprintf( char *bf, const char *frmt, va_lst arg ); |
|
#3
| ||||
| ||||
| Re: Implementation of vsprintf() : C
I guess you know atleast about Library function. Under control of the format control string the vsprintf() function formats data and also writes the result to buffer. The format string is described under the description of the printf() function. With the variable argument list replaced with arg so the vsprintf() function is equivalent to the sprintf() function, which has been initialized by the va_start() macro. The vsprintf() function returns the number of characters or a negative value if an output an error occurred. |
|
#4
| ||||
| ||||
| Re: Implementation of vsprintf() : C
The following program shows that the use of the vsprintf() function in a general error message routine : #include <stdio.h> #include <stdarg.h> #include <string.h> char msgbf[80]; char *fmtmsg( char *frmt, ... ) { v_lst arglst; v_strt( arglst, frmt ); strcpy( msgbf, "Error: " ); vsprintf( &msgbf[7], frmt, arglst ); v_end( arglst ); return( msgbf ); } void main() { char *mg; mg = fmtmsg( "%s %d %s", "Failed", 100, "times" ); printf( "%s\n", mg ); } |
|
#5
| ||||
| ||||
| Re: Implementation of vsprintf() : C
Here, one more example of code of vsscanf() function : #include <crtdll/stdio.h> #include <stdarg.h> #include <limits.h> #include <crtdll/internal/file.h> int vsprintf(char *str, const char *fmt, va_list ap) { FILE F; int lent; F._flag = _IOWRT|_IOSTRG; F._ptr = str; F._cnt = INT_MAX; F._file = -1; lent = vfprintf(&f,fmt, ap); *f._ptr = 0; return lent; } |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Implementation of vsprintf() : C" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| network implementation | jonnitwo | Networking & Security | 1 | 17-03-2011 12:37 AM |
| Implementation of mkdir() : C | Agustíne | Software Development | 4 | 02-02-2010 06:16 PM |
| C : Implementation of ctime() | Gavyn | Software Development | 4 | 01-02-2010 04:21 PM |
| Implementation of vsscanf() : C | Garrett | Software Development | 4 | 28-01-2010 10:58 AM |
| Implementation of mysql | Aloke | Software Development | 5 | 23-01-2010 01:26 AM |