Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , ,

Sponsored Links



Implementation of vsprintf() : C

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 28-01-2010
Member
 
Join Date: Dec 2009
Posts: 25
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.
Reply With Quote
  #2  
Old 28-01-2010
Modifier's Avatar
Member
 
Join Date: Jan 2008
Posts: 1,502
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 );
Reply With Quote
  #3  
Old 28-01-2010
absolute55's Avatar
Member
 
Join Date: Nov 2005
Posts: 1,238
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.
Reply With Quote
  #4  
Old 28-01-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
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 );
}
Reply With Quote
  #5  
Old 28-01-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
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;
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 05:16 AM.