Questions tagged [itoa]

Questions about itoa function may have this tag. Despite being supported by some compilers, this function is not defined in ANSI-C and it is not part of C++.

94 questions
4
votes
1 answer

Issue with itoa() and char array in regards to C (interfacing an LCD)

Doing my best to be brief; I am trying to program an LCD to print out an integer variable (of more than 1 digit). I'm trying to do this using the itoa function as the LCD takes ASCII characters. The below code compiles and prints "Set Temp: " when I…
James
  • 356
  • 2
  • 13
4
votes
1 answer

ANSI C, integer to string without variadic functions

I'm currently working with a PLC that supports ANSI C, but uses its own flavour of the GNU compiler, which doesn't compile any variadic functions and things like itoa. So using sprintf & co. isn't an option for converting integers to strings. Can…
Maxwin
  • 383
  • 3
  • 17
4
votes
2 answers

Unsigned int into a char array. Alternative to itoa?

I have a question about unsigned ints. I would like to convert my unsigned int into a char array. For that I use itoa. The problem is that itoa works properly with ints, but not with unsigned int (the unsigned int is treaded as a normal int). How…
Ganjira
  • 966
  • 5
  • 16
  • 32
3
votes
4 answers

Converting integer to binary string using itoa in C/C++

Can I use itoa() for converting long long int to a binary string? I have seen various examples for conversion of int to binary using itoa. Is there a risk of overflow or perhaps loss of precision, if I use long long int? Edit Thanks all of you for…
Mayank Kataria
  • 33
  • 1
  • 1
  • 5
3
votes
1 answer

convert int to char* in standard C (without itoa)

I have declared and initialized two variables as shown below: int a=5; char* str; str = (char*)calloc(255, sizeof(char)); I want to convert the int to char* in standard C. I cannot use any conversion function from C++ such itoa. I am using Ubuntu…
Alexandru N. Onea
  • 423
  • 2
  • 6
  • 18
3
votes
2 answers

Convert usigned integer( uint16_t) to string. Standard itoa base 10 is giving negative values

I need to convert uint16_t value to a string. I want the string to be a decimal respresentation of the number. Example: uint16_t i=256 string: 256 I tried with itoa(i,string, 10) but when i value increases starts printing negative values. I send the…
user3278790
  • 75
  • 1
  • 3
  • 9
3
votes
4 answers

Can I reuse the same buffer for subsequent itoa() calls?

I'm wondering if this is safe/sanctioned usage: char pBuf[10]; itoa(iInt, pBuf, 10); // pBuf value gets copied elsewhere //memset(pBuf, 0, sizeof(pBuf)); // Is this necessary? itoa(iInt2, pBuf, 10); // pBuf value gets copied elsewhere Can I reuse…
Enigma
  • 1,247
  • 3
  • 20
  • 51
2
votes
1 answer

simulate ulltoa() with a radix/base of 36

I need to convert an unsigned 64-bit integer into a string. That is in Base 36, or characters 0-Z. ulltoa does not exist in the Linux manpages. But sprintf DOES. How do I use sprintf to achieve the desired result? i.e. what formatting % stuff? Or if…
unixman83
  • 9,421
  • 10
  • 68
  • 102
2
votes
4 answers

uint64_t to an array - C language

I tried to parse uint64_t array to an array of char (result in decimal, separated by comma). I used memcpy, every time I get a random values. iota() function converts max uint32_t values. I tried separate uint64_t to 2 uint32_t, but I never get a…
maghost
  • 39
  • 1
  • 7
2
votes
2 answers

How do I fix my `itoa` implementation so it doesn't print reversed output?

I want to convert an integer into a string of numeric characters in C. I've tried using itoa, but it's non-standard and not provided by my C library. I tried to implement my own itoa, but it's not working properly: #include #include…
S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
2
votes
2 answers

Trying to understand itoa function

I tried to re-write the itoa() function from K&R exercises, but I failed to define it. I see the answer of the function in the library , but I can't understand what is inside the do block. Please explain it to me. Thanks! /* itoa: convert n to…
2
votes
3 answers

Formatting: how to convert 1 to “01”, 2 to “02”, 3 to "03", and so on

Following code outputs the values in time format, i.e. if it's 1:50pm and 8 seconds, it would output it as 01:50:08 cout << "time remaining: %02d::%02d::%02" << hr << mins << secs; But what I want to do is (a) convert these ints to char/string (b)…
Daqs
  • 720
  • 3
  • 8
  • 28
2
votes
1 answer

VBScript to convert integer to string (itoa)

I have written a method to take an integer and convert it to either decimal, hex, or binary depending on what you choose using commenting. I will build a choice in later. The problem I am having is that the wrong values are being chosen and I think…
BDMurphy
  • 23
  • 5
2
votes
4 answers

Base Conversion Problem

I'm trying to convert an integer to a string right now, and I'm having a problem. I've gotten the code written and working for the most part, but it has a small flaw when carrying to the next place. It's hard to describe, so I'll give you an…
jakogut
  • 4,409
  • 6
  • 29
  • 41
2
votes
5 answers

guide me in dividing the number by 10 and later converting into a string

#include int main() { int num = 255; num = num / 10; char buf[5]; itoa(num, buf,10); printf("%s", buf); return 0. } I am trying to divide the integer number by 10 but I am getting a solution of 25 ( I should get 25.5). Later I am…