C language: simulates printf. required functions: print (& quot; ccc \ ts! & Quot;, & #039; B & #039;, & #039; I & #039;, & #039; t & #039;, & quot; welcome to you & quot ;);

Source: Internet
Author: User

C language: Simulate printf. required function: print ("ccc \ ts! ", 'B', 'I', 't'," welcome to you ");
Program:

# Include <stdio. h> # include <stdlib. h> # include <stdarg. h> int my_printf (const char * fmt ,...) {const char * s; char c; va_list ap; // parameter list va_start (ap, fmt); // get the fmt pointer to apwhile (* fmt) {/* if (* fmt! ='S '| * fmt! = 'C') {putchar (* fmt ++); continue;} */switch (* fmt) {case's ': s = va_arg (ap, const char *); // get the parameter for (; * s; s ++) // print the string content {putchar (* s) through a loop;} break; case 'C': c = va_arg (ap, char); putchar (c); break; default: putchar (* fmt); break;} fmt ++ ;} va_end (ap); // set 0} int main () {char a = 'B'; my_printf ("ccc \ ts! ", 'B', 'I', 't'," welcome to you "); system (" pause "); return 0 ;}

 

Result: bit welcome to you! Press any key to continue...

Related Article

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.