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
2
votes
2 answers

What is the technical reason this _itoa_s fails?

I'm trying to convert the digit's 0 to 9 to ASCII using _itoa_s and I find myself running into stack corruption errors using MSVC2012. I thought that the ASCII table only occupied one byte per character, but from the looks of things, one byte isn't…
Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
1
vote
1 answer

Itoa stopping strcat from properly appending

I am trying to append a series of char arrays in Arduino C++. I have a char array "outputString", and a series of other char arrays that I with to append with via strcat. I also have a checkSum generator that generates the checksum and I used Itoa…
HFOrangefish
  • 267
  • 1
  • 10
1
vote
1 answer

How to write a variadic function in C that takes integers and returns them all together in a dynamic string?

For example: char* function(int n, ...); //prototype main() { char* s; s= function(3, 123, 456, 789); printf("%s", s); } How do i write this function that will take integers and return a dynamic string of these integers? While trying to solve…
1
vote
1 answer

Atoi() vulnerability against fault injection

I’m using atoi to convert an string to integer in a embedded c application. However, I could exploit the vulnerability in atoi() using clock glitching fault injection attack. I mean when I have a single or multiple glitch, the processor missed some…
elik1991
  • 73
  • 1
  • 8
1
vote
1 answer

Segfault when trying to recode itoa in C

Newbie trying to recode itoa here. I am not quite sure about how the itoa function works, but here's how I want mine to work for now : char *ft_itoa(int nb, char *str) I want each digit of nb to be converted into a char which is to be put in…
badakzz
  • 35
  • 6
1
vote
0 answers

Is there a replacement for '_itoa_s' function in C++

Found this old source for a autoclicker, I wanted to edit and tweak a few strings, so it would be a bit easier for accessibility reasons. https://gist.github.com/iGlitch/c55043119fce86e7bf04efc3aae1b5bf But just trying to compile the code as it is,…
Koppis
  • 109
  • 8
1
vote
4 answers

Why does itoa expect a signed character instead of an unsigned?

Learning embedded C while working in MPLAB X with a PIC24FJ128GB204. So far, I've mostly heard that you should use unsigned types as much as possible (especially?) on embedded devices, so I've started to use uint8_t arrays to hold strings. However,…
1
vote
3 answers

converting integer to string C++

I am trying to convert an integer to char array and I came across this piece of code int i = 5; std::string s; std::stringstream out; out << i; s = out.str(); But when I try to print the value of s it still prints 5. I don't know if its supposed to…
Max Eastman
  • 33
  • 2
  • 4
1
vote
1 answer

Does itoa delete char?

Why does this give me a memory error? char* aVar= new char; itoa(2, aVar, 10); delete aVar; Does itoa delete the aVar? How to know if a C++ function deletes the pointer, is there a convention about that? If I do this then error doesn't occur: char*…
okami
  • 2,093
  • 7
  • 28
  • 40
1
vote
2 answers

C int to char array on Mac OS X

I'm trying to convert an int to a char*. I'm on a Mac OS X so I can't use itoa, since it's non-standard, I'm trying to use sprintf or snprintf but I keep on getting segmentation fault: 11. Here's what I've got: snprintf(msg, sizeof(char *), "%d",…
C. Porto
  • 631
  • 3
  • 12
  • 26
1
vote
1 answer

itoa using reverse(string) code showing error

Why doesn't ANSI C use strrev instead of creating such a big reverse function? This code is showing me an error. Please correct it. What is the error. I am using Code::Blocks Error message that I…
user3754207
1
vote
2 answers

How to add an multidigit int and a char, where the output will be int + char

this is what I have so far Header file reads: string MyAdd(int A, char B) { char C[10]; itoa(A,C,10); C[1] = '+'; C[2] = B; C[3] = '\0'; return C; } Calling program: cout << "\n\t\tThe…
user3185727
  • 159
  • 1
  • 3
  • 12
1
vote
4 answers

itoa recursively

I have been trying to write a recursive version of function itoa, the code is shown below. void itoa(int n, char s[]) { static int i = 0; if(n / 10 != 0) itoa(n/10, s); else if(n < 0) i = 1; /* s[0] is allready…
Tool
  • 12,126
  • 15
  • 70
  • 120
1
vote
1 answer

Converting uint16 from ADC flips negative

What I want to do: Turn the resulting 16bit number (after combining the two 8bit #s) into a string to use with my serial send function The problem: When using itoa, the result becomes negative once it passes the half way point (passing from the 15th…
Nick Yang
  • 13
  • 2
1
vote
2 answers

Reversing a string with strrev - C

I'm trying to reverse a string using the function strrev(). I know that strrev returns a pointer to the reversed string so I simply initialize an already allocated string with same size as the original one with the strrev function return. Obviously…
Arlind
  • 436
  • 2
  • 9
  • 22