Your own user defined "printf" function
#include<stdio.h>
#include<stdarg.h>
#include<conio.h>
int fun(int n)
{
if(n==0)
return 0;
else
{
fun((int)n/10);
putchar((n%10)+48);
}
}
void print(char *f,...)
{
int i;
va_list p;
va_start(p,f);
while(*f!=NULL)
{
if(*f=='%')
{
f++;
switch(*f)
{
case 'd':
fun((va_arg(p,int)));
f++;
break;
case 'c':
putchar(va_arg(p,int));
f++;
break;
case '%':
putchar('%');
f++;
}
}
else
{
putchar(*f);
f++;
}
}
}
void main()
{
char c='I';
int n;
clrscr();
print("Hallo cant you go with us??????\n");
print("Output is 1st:%d\t2nd:%d\t3rd:%d",4,3,85);
print("\nOutput is %c",c);
printf("\nEnter the number:");
scanf("%d",&n);
printf("Here is %d",n);
getch();
}
#include<stdio.h>
#include<stdarg.h>
#include<conio.h>
int fun(int n)
{
if(n==0)
return 0;
else
{
fun((int)n/10);
putchar((n%10)+48);
}
}
void print(char *f,...)
{
int i;
va_list p;
va_start(p,f);
while(*f!=NULL)
{
if(*f=='%')
{
f++;
switch(*f)
{
case 'd':
fun((va_arg(p,int)));
f++;
break;
case 'c':
putchar(va_arg(p,int));
f++;
break;
case '%':
putchar('%');
f++;
}
}
else
{
putchar(*f);
f++;
}
}
}
void main()
{
char c='I';
int n;
clrscr();
print("Hallo cant you go with us??????\n");
print("Output is 1st:%d\t2nd:%d\t3rd:%d",4,3,85);
print("\nOutput is %c",c);
printf("\nEnter the number:");
scanf("%d",&n);
printf("Here is %d",n);
getch();
}
0 comments:
Post a Comment
You are most welcome for making comments here. I will consider your view and will reply you soon.