How to printf variable?
-
- Posts: 1
- Joined: Tue Jan 12, 2021 11:09 am
How to printf variable?
I am using printf from Meaty Skeleton (https://wiki.osdev.org/Meaty_Skeleton). After some changes of terminal_putchar, it works fine, when I'm writing ready string (printf("Hello\n") gives me "Hello" output), but when I use variable (printf(a), where's a is char), it gives me random symbols. How to make it say variable value? (I am using i686-elf-gcc)
Re: How to printf variable?
It sounds like you're trying to pass a char as an argument to a function that takes a pointer. At the risk of sounding harsh, this is a very basic C thing and if you don't see how this is wrong you'll have a difficult time moving forward with OS dev.but when I use variable (printf(a), where's a is char),
Re: How to printf variable?
The first argument must be a zero terminated string which specifies the formating. Are you sure the compiler didn't gave you a warning about using "printf(a)"?UserUserUserUserUser wrote:when I use variable (printf(a), where's a is char), it gives me random symbols.
Depends on the variable.UserUserUserUserUser wrote:How to make it say variable value?
Code: Select all
printf("%c\n", a); // print char
printf("%d\n", i); // print integer in decimal
printf("%x\n", i); // print integer in hexadecimal
printf("%s\n", s); // print another string
... etc.
I don't want to be harsh either, but klange is right.klange wrote:At the risk of sounding harsh, this is a very basic C thing and if you don't see how this is wrong you'll have a difficult time moving forward with OS dev.
Cheers,
bzt