Suppose I have an char array m, and I want to add an int value z into it, how do I convert z into a char so that I can put it into the array? Also, how could I print out the array in reverse? This is in C, NOT C++.
How do I convert ints to chars, and print out an array in reverse?
Collapse
X
-
Tags: None
-
Please provide a short example so I understand what you want to do: initial contents of m[], value of z, final contents of m[]. In particular, please make it clear whether m[] contains character values (like '3') or small integer values (like 10). If it contains character values, then is it simply an array or is it a string? In a string, there are typically fewer meaningful characters than there are slots in the array; the end of the meaningful characters is indicated by a null character ('\0').Comment
-
The initial contents of m[] are blank but there are 100 slots, all blank for chars to be inserted in. I am trying to convert a number n to a base b (2-16), so z is a temporary number used to insert a number, or character into the array m[]. m could contain digits 0-9, and letters a-f lowercase.Comment
-
Comment
-
In C, a string is an array of characters which ends with a NUL character '\0' so the string s[16]represents the array below.(15 characters + NUL)
So if char* s = "0123456789abcd e" that is s has a type pointer to a character then:
Code:cout<<s<<endl; //prints 0123456789abcde
You could use a for loop to print out the array in reverse by starting at the [end-1]and printing each element until you reach s[0]Comment
Comment