Results 1 to 5 of 5

Thread: Implementation of vsprintf() : C

  1. #1
    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.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    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. #3
    Join Date
    Nov 2005
    Posts
    1,323

    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. #4
    Join Date
    May 2008
    Posts
    2,297

    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. #5
    Join Date
    Apr 2008
    Posts
    2,005

    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;
    }

Similar Threads

  1. Implementation of mkfifo() : C
    By Garett in forum Software Development
    Replies: 4
    Last Post: 02-02-2010, 07:27 PM
  2. Implementation of mkdir() : C
    By Agustíne in forum Software Development
    Replies: 4
    Last Post: 02-02-2010, 06:16 PM
  3. C : Implementation of ctime()
    By Gavyn in forum Software Development
    Replies: 4
    Last Post: 01-02-2010, 04:21 PM
  4. C : Implementation of sin(),pow(),sqrt()
    By Adolfa in forum Software Development
    Replies: 4
    Last Post: 30-01-2010, 12:41 PM
  5. Implementation of mysql
    By Aloke in forum Software Development
    Replies: 5
    Last Post: 23-01-2010, 01:26 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,881,886.89266 seconds with 16 queries