Q:printf() and scanf().... 
Author Message
 Q:printf() and scanf()....

Quote:

> Hi.
> an ordinary function's prototype such as add() function would be:

[snip]

Quote:
> but what's the prototype of standard function like prinf() or scanf()??
> because I think they can have variant number of parameters.

    Well, the prototype for printf is:

int printf(const char *format, ...);

Quote:
> and when the compiler work with this parameters, how does it do that?

    Well, read the FAQ, < http://www.*-*-*.com/ ~scs/C-faq/s15.html>,
specifically 15.4.

--
Clark S. Cox, III

http://www.*-*-*.com/



Mon, 28 Apr 2003 03:00:00 GMT  
 Q:printf() and scanf()....
Hi.
an ordinary function's prototype such as add() function would be:

int add(int, int);

so when I call it, it would be like:

int main()
{
  int a;
  a = add(10, 20);

Quote:
}

but what's the prototype of standard function like prinf() or scanf()??
because I think they can have variant number of parameters. like:

printf("%d %d", 10, 20);
printf("Hello world!");

and when the compiler work with this parameters, how does it do that?



Tue, 29 Apr 2003 11:48:13 GMT  
 Q:printf() and scanf()....

Quote:

> but what's the prototype of standard function like prinf()

int printf(char const *, ...);

Quote:
> or scanf()??

int scanf(char const *, ...);

Quote:
> and when the compiler work with this parameters, how does it do that?

look in your manual for the va_start, va_arg and va_end macros, which all
deal with the va_list (variadic argument list) type.  they are defined in
the standard header file stdarg.h

if you have any further questions, post again.

--
 /"\                                                 m i k e   b u r r e l l

  X        AGAINST HTML MAIL,



Tue, 29 Apr 2003 12:05:55 GMT  
 Q:printf() and scanf()....

Quote:

> Hi.
> an ordinary function's prototype such as add() function would be:
> int add(int, int);
> so when I call it, it would be like:
> int main()
> {
>   int a;
>   a = add(10, 20);
> }
> but what's the prototype of standard function like prinf() or scanf()??

You can find these in stdio.h.

Quote:
> because I think they can have variant number of parameters. like:
> printf("%d %d", 10, 20);
> printf("Hello world!");
> and when the compiler work with this parameters, how does it do that?

By taking advantage of variable argument lists. You can find a description
of these at http://man-pages.net/linux/man3/stdarg.3.html, but K&R's is
probably better.

--

   char *sites[]={"http://www.freezersearch.com/index.cfm?aff=dhc",
   "http://www.ciscllc.com","http://www.freezemail.com",0};



Tue, 29 Apr 2003 12:07:01 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. questions about sprintf, sscanf, printf, scanf, fscanf, fprintf!

2. Simple scanf/printf question

3. skipped printf/scanf ???

4. tiny question on format of scanf and printf

5. Examples of format strings for scanf/printf ?

6. scanf/printf conversions

7. pointers in scanf and printf

8. Beginner question - printf and scanf

9. printf() and scanf()

10. casting printf/scanf

11. printf and scanf in IBMC on IBM 3090

12. printf/scanf trouble on SPARCstation

 

 
Powered by phpBB® Forum Software