Jak wydrukować "unsigned long" w C?
Nigdy nie rozumiem, jak wydrukować unsigned long
typ danych w C.
Załóżmy, że unsigned_foo
jest unsigned long
, wtedy próbuję:
printf("%lu\n", unsigned_foo)
printf("%du\n", unsigned_foo)
printf("%ud\n", unsigned_foo)
printf("%ll\n", unsigned_foo)
printf("%ld\n", unsigned_foo)
printf("%dl\n", unsigned_foo)
I wszystkie wypisują jakiś -123123123
Numer zamiast unsigned long
, który mam.
7 answers
%lu
jest prawidłowym formatem unsigned long
. Wygląda na to, że są tu inne problemy, takie jak uszkodzenie pamięci lub niezainicjowana zmienna. Może pokaż nam szerszy obraz?
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-07-09 04:50:19
Ze wszystkich kombinacji, które próbowałeś, %ld
i %lu
są jedynymi, które są w ogóle poprawnymi specyfikatorami formatu printf. %lu
(long unsigned decimal), %lx
lub %lX
(long hex z małymi lub dużymi literami) i %lo
(long octal) są jedynymi poprawnymi specyfikatorami formatu dla zmiennej typu unsigned long (oczywiście możesz dodać modyfikatory szerokości pola, precyzji itp. pomiędzy %
i l
).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-07-09 06:00:14
-
%lu
for unsigned long -
%llu
for unsigned long long
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-07-12 15:01:16
Dla int %d
For long int %ld
Dla long long int %lld
For unsigned long long int %llu
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-04-07 10:31:44
int main()
{
unsigned long long d;
scanf("%llu",&d);
printf("%llu",d);
getch();
}
To będzie pomocne . . .Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-28 03:25:57
Format to %lu
.
Proszę sprawdzić inne typy danych i ich użycie w printf tutaj
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-08-02 17:37:15
Poprawnym specyfikatorem dla unsigned long jest %lu
.
Jeśli nie otrzymujesz dokładnej wartości, której oczekujesz, mogą wystąpić pewne problemy w Twoim kodzie.
Proszę skopiować kod tutaj. Może ktoś powie Ci lepiej, w czym tkwi problem.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-04-09 18:33:51