This shows you the differences between two versions of the page.
|
playground:c:stdio.h:printf [2017/07/30 01:49] Daniel Gohlke created |
playground:c:stdio.h:printf [2024/02/16 01:12] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | {{keywords>wiki library source code example reference}} | ||
| - | ==== C Example Sourcecode ==== | + | ===== printf ===== |
| <code c> | <code c> | ||
| - | #include <stdio.h> | + | #include <stdio.h> /* including standard library */ |
| - | + | //#include <windows.h> /* uncomment this for Windows */ | |
| - | int main(int **argc, char **argv) | + | |
| - | { | + | |
| - | /* | + | |
| - | * Sourcecode example for printf | + | |
| - | * https://code-reference.com/c/stdio.h/printf | + | |
| - | */ | + | |
| - | int i; | + | |
| - | /* Click on int to look what it is */ | + | |
| - | i=0; | + | |
| - | while (1) { | + | int printf ( const char * restrict format, ... ); |
| - | /* Click on while to read the description of while*/ | + | </code> |
| - | i++; | + | |
| - | printf("Hello World no: %i\n",i); | + | ==== Arguments ==== |
| - | /* Click on printf to read the description of printf*/ | + | The function printf prints format to STDOUT\\ |
| - | } | + | |
| + | Code Description\\ | ||
| + | **%c** character value\\ | ||
| + | **%s** string of characters\\ | ||
| + | **%d** signed integer\\ | ||
| + | **%i** signed integer\\ | ||
| + | **%f** floating point value\\ | ||
| + | **%e** scientific notation, with a lowercase "e"\\ | ||
| + | **%E** scientific notation, with a uppercase "E"\\ | ||
| + | **%g** use **%e** or **%f**\\ | ||
| + | **%G** use **%E** or **%f** \\ | ||
| + | **%o** octal\\ | ||
| + | **%u** unsigned integer\\ | ||
| + | **%x** unsigned hexadecimal, with lowercase letters\\ | ||
| + | **%X** unsigned hexadecimal, with uppercase letters\\ | ||
| + | **%p** a pointer\\ | ||
| + | **%n** the argument shall be a pointer to an integer in which the number of characters written is placed\\ | ||
| + | **%%** shall be a **%** sign\\ | ||
| + | |||
| + | \n (newline) | ||
| + | \t (tab) | ||
| + | \v (vertical tab) | ||
| + | \f (new page) | ||
| + | \b (backspace) | ||
| + | \r (carriage return) | ||
| + | \n (newline) | ||
| + | |||
| + | |||
| + | ===== C Sourcecode Example ===== | ||
| + | <code c> | ||
| + | /* | ||
| + | * printf example code | ||
| + | * http://code-reference.com/c/stdio.h/printf | ||
| + | */ | ||
| + | |||
| + | #include <stdio.h> /* including standard library */ | ||
| + | //#include <windows.h> /* uncomment this for Windows */ | ||
| + | |||
| + | int main ( void ) { | ||
| + | |||
| + | int number; | ||
| + | number=42; | ||
| + | |||
| + | printf("the answer to life the universe and everything is %i \n", number); | ||
| + | |||
| + | return 0; | ||
| } | } | ||
| + | |||
| </code> | </code> | ||
| - | === Output example for a compiled source === | + | ==== output ==== |
| + | |||
| + | |||
| + | the answer to life the universe and everything is 42 | ||
| + | |||
| + | |||
| + | |||
| - | output: | ||
| - | |||
| - | user@comp:$ ./te | ||
| - | Hello World no: 1 | ||
| - | Hello World no: 2 | ||
| - | Hello World no: ... | ||
| - | ... and so on, and so on | ||