Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef PRINTF_SIMULATOR_H_INCLUDED
- #define PRINTF_SIMULATOR_H_INCLUDED
- #include<iostream>
- #include<cstdarg>
- #include<cstdlib>
- #include<cstring>
- using namespace std;
- void move_forward(char y[], int position);
- void print(char x[], ...)
- {
- va_list contor;
- char number[15], y[1000];
- int aux, i, k=0;
- for(int i=0; x[i]; i++)
- {
- y[i] = x[i];
- }
- y[strlen(x)] = '\0';
- va_start(contor,x);
- for(i=0; y[i]!='\0'; i++)
- {
- if((y[i] == '%')&&(y[i+1] == 'd'))
- {
- aux = va_arg(contor, int);
- itoa(aux, number, 10);
- if(strlen(number) > 1)
- {
- for(int p=1; p<=strlen(number)-2 ; p++)
- {
- move_forward(y, i);
- }
- k = i;
- for(int q = 0; number[q]; q++)
- {
- y[k] = number[q];
- k++;
- }
- i = i+strlen(number)-2;
- }
- else if(strlen(number) == 1)
- {
- y[i] = number[0];
- for(int p = i+1; y[p]; p++)
- {
- y[p] = y[p+1];
- }
- }
- }
- }
- cout<<y;
- va_end(contor);
- }
- void move_forward(char y[], int position)
- {
- int n;
- n = strlen(y);
- for(int l = n; l>=position; l--)
- {
- y[l+1] = y[l];
- }
- }
- #endif // PRINTF_SIMULATOR_H_INCLUDED
- /* Code::Example::
- #include<iostream>
- #include"printf_simulator.h"
- using namespace std;
- int main()
- {
- int a, b;
- a = 5;
- b = 2;
- print("This is the value %d and this is %d", a, b);
- return 0;
- }
- It will print on the screen: This is the value 5 and this is 2
- _________Designed, Developped, Created by [[<<<Ionita Cosmin>>>]]_________(http://www.kosvip.webs.com) -> For more information (including contact)______*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement