Sprintf, swprintf, _ stprintf

Source: Internet
Author: User
// Crt_sprintf.c // compile with:/W3 // This program uses sprintf to format varous // data and place them in the string named buffer. # include <stdio. h> int main (void) {char buffer [200], s [] = "computer", c = 'l'; int I = 35, J; float fp = 1.7320534f; // format and print various data: J = sprintf (buffer, "string: % s \ n", S); // c4996 J + = sprintf (buffer + J, "Character: % C \ n", c); // c4996 J + = sprintf (buffer + J, "INTEGER: % d \ n", I ); // c4996 J + = sprintf (buffer + J, "Real: % F \ n", FP); // c4996 // Note: sprintf is deprecated; consider using sprintf_s instead printf ("output: \ n % s \ ncharacter COUNT = % d \ n", buffer, J );} /*************************************** * *********** // crt_swprintf.c // wide character example // also demonstrates swprintf returning error code # include <stdio. h> int main (void) {wchar_t Buf [100]; int Len = swprintf (BUF, 100, l "% s", l "Hello World "); printf ("wrote % d characters \ n", Len); Len = swprintf (BUF, 100, l "% s", l "Hello \ xFFFF world "); // swprintf fails because string contains Weof (\ xFFFF) printf ("wrote % d characters \ n", Len );} /*************************************** * ************/void cmainframe:: ontest () {// generic editiontchar Buf [200]; int Len = _ stprintf (BUF, _ T ("string 1: % s \ n "), _ T ("Medium A"); Len + = _ stprintf (BUF + Len, _ T ("string 2: % d"), 1); MessageBox (BUF ); // MessageBox (_ T ("Main Frame on test clicked "));}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.