hello, this is gireesh.
can u pls give me solution to this question.
PLATFORM : C language
Q. What are the input arguments passed to the printf() function?
actually i found in header file i.e;
extern int printf(const *char, ....);
what is the meaning of .... in printf function?
pls give me reply as early as possible.
my email id : <snipped>
3 2436
hello, this is gireesh.
can u pls give me solution to this question.
PLATFORM : C language
Q. What are the input arguments passed to the printf() function?
actually i found in header file i.e;
extern int printf(const *char, ....);
what is the meaning of .... in printf function?
pls give me reply as early as possible.
my email id : tgiree@gmail.com
... is used to get variable length arguments. these arguments are retrieved using some macros and functions declared in stdarg.h
You can have your own print like this -
void
-
miniprintf(const char *fmt, ...)
-
{
-
const char *p;
-
int i;
-
unsigned u;
-
char *s;
-
va_list argp;
-
-
va_start(argp, fmt);
-
-
for(p = fmt; *p != '\0'; p++) {
-
if(*p != '%') {
-
putchar(*p);
-
continue;
-
}
-
-
switch(*++p) {
-
case 'c':
-
i = va_arg(argp, int);
-
/* *not* va_arg(argp, char); see Q 15.10 */
-
putchar(i);
-
break;
-
-
case 'd':
-
i = va_arg(argp, int);
-
if(i < 0) {
-
/* XXX won't handle INT_MIN */
-
i = -i;
-
putchar('-');
-
}
-
fputs(baseconv(i, 10), stdout);
-
break;
-
-
case 'o':
-
u = va_arg(argp, unsigned int);
-
fputs(baseconv(u, 8), stdout);
-
break;
-
-
case 's':
-
s = va_arg(argp, char *);
-
fputs(s, stdout);
-
break;
-
-
case 'u':
-
u = va_arg(argp, unsigned int);
-
fputs(baseconv(u, 10), stdout);
-
break;
-
-
case 'x':
-
u = va_arg(argp, unsigned int);
-
fputs(baseconv(u, 16), stdout);
-
break;
-
-
case '%':
-
putchar('%');
-
break;
-
}
-
}
-
-
va_end(argp);
-
}
-
Note : This code has been copied from c faq
... is known as ellipsis operator
Banfa 9,065
Expert Mod 8TB
... is used to get variable length arguments.
For clarification the arguments are not variable length (it is not possible for arguments to be of variable length). It is the number of arguments that is variable.
... is used to indicated that an unspecified number of extra arguments can be present in the function call.
Functions using the elipsis to indicate a variable number of function arguments are called varidac functions.
Make that 'variadic' ;-)
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steven Bethard |
last post by:
So I end up writing code like this a fair bit:
map = {}
for key, value in sequence:
map.setdefault(key, ).append(value)
This code basically constructs a one-to-many mapping -- each value that...
|
by: rejeesh |
last post by:
Hi,
I need a 'wrapper' function for printf. So that anywhere in my program
if i call the wrapper function it does the same thing as the regular
printf function, but puts a custom message at the...
|
by: Amit Sharma |
last post by:
Hi,
I wanted to know when we call function with argument, Does the
arguments stored in stack always or it compiler specific and could be
stored in queue
e.g. Does this program's output depends...
|
by: sunfiresg |
last post by:
During an interview, I am asked to answer a question:
Printf is a major formatted output function provided by the standard C
library. Printf accepts a formatting string followed by a various...
|
by: dragoncoder |
last post by:
Consider the following code.
#include <stdio.h>
int main()
{
int i =1;
printf("%d ,%d ,%d\n",i,++i,i++);
return 0;
}
|
by: sam_cit |
last post by:
Hi Everyone,
I have the following code,
int main()
{
int p = {10,20,30,40,50};
int *i = &p;
printf("before : %p\n",(void*)i);
printf("1 %d %d\n",*++i,*i++);
|
by: sam_cit |
last post by:
Hi Everyone,
int main()
{
printf("not included stdio.h");
}
Yes, i haven't included stdio.h and my compiler would generate a
warning and would assume that it would return a int, my question...
|
by: sam_cit |
last post by:
Hi Everyone,
I have the following custom printf() function in the my program unit
and when i execute the program, the actual printf() function is invoked
and i get no error, no warning. However...
|
by: vlsidesign |
last post by:
Example
printf("I have %d cars. \n", 10);
Is it more correct to say that the printf function doesn't insert the
integer, rather into changes the integer into chars and then inserts
it?
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |