Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdio.h>
- #include <cstdlib>
- #include <stdarg.h>
- #include <iostream>
- #include <vector>
- using namespace std;
- void sc(char *format, ...);
- struct complex
- {
- int real, img;
- };
- int main() {
- sc("%d%f%r%i", 9, 8.5, 1, -3);
- system("pause");
- return 0;
- }
- void sc(char *format, ...) {
- int i_val;
- double d_val;
- struct complex a;
- va_list ap;
- va_start(ap, format);
- for (char *p = format; *p; p++)
- {
- if (*p == '%')
- {
- switch (*++p)
- {
- case 'd': i_val = va_arg(ap, int);
- cout << i_val << " "; break;
- case 'f': d_val = va_arg(ap, double);
- cout << d_val << " "; break;
- case 'r': a.real = va_arg(ap, int);
- cout << a.real; break;
- case 'i': a.img = va_arg(ap, int);
- cout << a.img <<"i"; break;
- default: cout << "ERROR"; break;
- }
- }
- else cout << *p << " ";
- }
- va_end(ap);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement