8

Why this code is not working?

#include <stdio.h>
main()
{
    UINT64_t ram = 90;
    printf("%d""\n", ram);
}

I got the Following errors:

In function \u2018main\u2019
error: \u2018UINT64_t\u2019 undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: expected \u2018;\u2019 before \u2018ram\u2019
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Ramakant
  • 185
  • 1
  • 3
  • 10
  • 3
    `#include ` and `uint64_t` – Gopi May 07 '15 at 05:49
  • i got again same errors. – Ramakant May 07 '15 at 05:51
  • Did you change `uint64_t`? – Gopi May 07 '15 at 05:54
  • 1
    `uint64_t`, note the case. And the proper `printf` specifier for `uint64_t` is from ``, and uses literal-concatenation to form the proper spec, like this: `printf("%" PRIu64 "\n", val);` – WhozCraig May 07 '15 at 05:54
  • i wana to use UINT64_t, not the uint64_t... because the code is already wriiten. i got problem in testing. – Ramakant May 07 '15 at 05:56
  • 2
    UINT64_t isn't a standard type or alias. Unless you typedef it yourself, you're going to get it from somewhere else. Ask the guy that gave you the code. The *standard* supplied version is `uint64_t`. – WhozCraig May 07 '15 at 05:58
  • Well, it looks like the code you give doesn't even compile, so you will have to extend that so that it includes the proper definitions for that type. However, I'd strongly advise against using non-standard types, as it makes your code less portable. That said, the output of the compiler is probably piped through something that doesn't properly handle Unicode (maybe implemented in Python?), the `\u2018` should be quote characters. – Ulrich Eckhardt May 07 '15 at 05:58
  • Note that there is no standard type `UINT64_t`; you need to include either `` or `` to get `uint64_t`, and you need `` to be able to print it. – Jonathan Leffler May 07 '15 at 05:59
  • do you know what `%d` is for? – phuclv May 07 '15 at 06:00

3 Answers3

13

uint64_t is defined in Standard Integer Type header file. ie, stdint.h. So first include stdint.h in your program.

Then you can use format specifier "%"PRIu64 to print your value: i.e.

printf("%" PRIu64 "\n", ram);

You can refer this question also How to print a int64_t type in C

Community
  • 1
  • 1
niyasc
  • 4,440
  • 1
  • 23
  • 50
  • 5
    Although `uint64_t` is defined in ``, the macros such as `PRIu64` are defined in `` instead. Unusually, `` effectively include ``; no other standard C header includes another. – Jonathan Leffler May 07 '15 at 05:57
4

Full working example: http://ideone.com/ttjEOB

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

int main()
{
    uint64_t ram = 90;
    printf("%" PRIu64 "\n", ram);
}

You forgot some headers, wrote incorrectly uint64_t and can't use %d with uint64_t

xanatos
  • 109,618
  • 12
  • 197
  • 280
2

Add:

#include <inttypes.h>

And use PRIu64 (outside of quotation marks like so):

printf("%"PRIu64"\n", ram);
ckolivas
  • 128
  • 7