Using sprintf() for example, it is no different from a normal C application. You may also use chprintf() but you need to create a stream writer to a string buffer.
Yes that is what I have tried before but the compiler doesn't seem to like the sprintf function . I don't know why.
Linking build/ch.elf c:/chibistudio/tools/gnu tools arm embedded/4.7 2013q2/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv7e-m\libc.a(lib_a-sbrkr.o): In function `_sbrk_r': sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk' collect2.exe: error: ld returned 1 exit status
This is because you must provide a _sbrk() implementation to the compiler. The compiler does not provide syscalls for a bare machine. the documentation is here: https://sourceware.org/newlib/libc.html#Syscalls
It is not complex, there is also an implementation under ./os/various/syscall.c but it was done for the YAGARTO compiler and must be adapted.
Using the word "cast" in this context tells me that you really need to figure out a bit of the fundamentals - like a couple of fundamental differences between primitive types and human-readable strings...