473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I convert ints to chars, and print out an array in reverse?

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++.
Sep 8 '10 #1
5 2092
Meetee
931 Expert Mod 512MB
Use sprintf function to insert number into array.

To print reverse array start from n(array length) instead of 0 in print loop.(In this case n should be n+1 after adding number in array)
Sep 8 '10 #2
donbock
2,426 Expert 2GB
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').
Sep 8 '10 #3
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.
Sep 8 '10 #4
I am new to C so I don't know what the sprintf function is, could you please explain it to me?
Sep 8 '10 #5
whodgson
542 512MB
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 = "0123456789abcde" that is s has a type pointer to a character then:
Expand|Select|Wrap|Line Numbers
  1. cout<<s<<endl; //prints 0123456789abcde
There is an article on this forum which explains arrays in more detail.
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]
Sep 9 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: hokieghal99 | last post by:
Hi, I'm trying to do this: ------------------------------ a="192." b="168." c="1." r = range(256) for r in r:
1
by: praba kar | last post by:
Dear all, In Php array_slice function base we can print array contents as per our desire eg) $a = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); $arr = array_slice($a,10,10); this function...
6
by: PHil Coveney | last post by:
Hello, I need to support a file format that stores integers with the MSB first and the LSB last. When I use BinaryWriter aWriter = new BinaryWriter(aFileStream, Encoding.ASCII); int someValue...
1
by: vsk | last post by:
Hai, I need to know how to convert an unsigned char array into hexstring. can anyone help me in this regard?. Thanks.
3
by: Wilfredo | last post by:
I have 25 numbers coming up from 1 to 25, now I want it to go from 25 to 1 with array.reverse. I get a reverse is not a member of array. Help
4
by: kvicky | last post by:
I have multiline textbox and I am trying to do a search functionality based on the input entered in this Textbox. I am able to convert into a string array if the search components are separated by...
2
by: Bilwin | last post by:
Hi friends, How can i convert StringTokenizer to string array? friends please reply me..
5
by: Maxim | last post by:
Hi all, I'm calling a COM Interface method that returnes SafeArray wrapped into variant. Is it possible to convert it to managed array? Because working with SAFEARRAY directly is a bit...
4
by: Man4ish | last post by:
HI , I am trying to convert string into char array of characters.but facing problem. #include <iostream> #include <string> using namespace std; int main() { string t="1,2,3,4,5,6";
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.