C/printf: Różnice pomiędzy wersjami
Przejdź do nawigacji
Przejdź do wyszukiwania
m
→Przykład użycia: format
m (→Problemy: format) |
m (→Przykład użycia: format) |
||
Wyjątkami są funkcje snprintf i vsnprintf, które zwracają liczbę znaków, które zostałyby zapisane do tablicy znaków, gdyby była wystarczająco duża.
===
<source lang="c">
#include <stdio.h>
ULLONG_MAX = 18446744073709551615 ; lMax = log2(ULLONG_MAX) = 64
</pre>
===zmienny format ===
<source lang=c>
// Akshay Hegde
// https://www.unix.com/programming/244285-passing-printf-formatting-parameters-variables.html
#include <stdio.h>
/* Following header files are not needed stdio.h is enough
#include <stdlib.h>
#include <string.h> */
#define red "\x1b[31m"
#define green "\x1b[32m"
#define yell "\x1b[33m"
#define blue "\x1b[34m"
#define magneta "\x1b[35m"
#define cyan "\x1b[36m"
#define reset "\x1b[0m"
int main () {
// Your value to be printed
float testvalue = 125.25;
// precision
int prec = 5;
// number of digits after decimal
int dig = 3;
// 'f' for float
char c = 'f';
// this holds your format string...("%s...%f") etc
char format[10];
// Here we are creating your fmt string
sprintf(format, "%%s%%%d.%d%c%%s\n", prec, dig,c);
// Finally printing with different colors
printf(format,red,testvalue,reset);
printf(format,blue,testvalue,reset);
}
</source>
===Uwagi===
|