Storing an integer in char * in C ++

I am writing code that returns an integer, which should then be printed using printw from the ncurses library. However, since printw only accepts char *, I cannot figure out how to output it.

Essentially, is there a way to store an integer in a char array, or print an integer using printw?

+6
c ++ arrays char integer ncurses
source share
4 answers

printw() takes const char * as a format specifier. Do you want to

 printw("%d",yournumber); 
+9
source share

The itoa function converts int to char *.

+1
source share

Use itoa () or sprintf () to convert an integer to an ascii string.

Example:

 char s[50]; sprintf(s, "%d", someInteger); 

now u can pass s as char *

0
source share

itoa will help you.

0
source share

All Articles