Computer problems,Computer help
*AX SOFT>>>Programming & Design

How can i convert the value of a array and put them in to a string?


in example,
in any state of my code i write array[i]=19;
then how can i put the value in a string and make string[i]=19?

in example,
in any state of my code i write array[i]=19;
then how can i put the value in a string and make string[i]='19'?
which show numeric 19 when i print the string (usring puts() or something else)

language C is to be used

okay.. in array[i] you have a number right? in your case it is 19.
an array can hold multi digit numbers at a single position but string is a array of characters and each position in a string can hold only 1 character. so string[i] can hold only one character. in cant hold '19' as it is made up of two characters '1' and '9'. if your number was made up of only one digit i.e.

array[i] = 2;

then you can follow the following format to put your number in the string[i] position as a character:

string[i] = array[i]+ '0' ; or string[i] = array[i] + 48;

here 48 is the integer value for the character '0' (zero). the integer value for '2' will be 2+48 = 50. for any integer number n shown as a char 'n' the integer value will be

'n' = n+48;
(char) (it's integer value);

when u assign the integer value of a character to a char variable or a string position, the compiler converts that number to its corresponding character before assigning.
when you do this with strings, remember to mark the end of your string with a '\0' as the compiler wont do it if u assign this way.

if you wish to put multi digit number in your string, you can break your numbers into single digits and assign them one by one or you can use the itoa(); function.

What?

You mean like -> string[i] = '19'; <- ???

what language are u using?

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • Given an integer value input,determine if that value is even or odd?

    void checkNumber(int number) { if(number is divisible by 2) print "The number is even"; else print "The number is odd"; }

    ...
  • Open source dev operating system.?

    Gnome is just one of the GUI for Linux. Mac OS X already has a far superior GUI. Open source more refers to the licencing agreement of the software written then it does the operating system. Bas...

  • Command prompt got messed up?

    try to check ur 'PATH' environment variable. It should have at least this: %SystemRoot%\system32;%SystemRoot%;

    ...
  • Can you make me a design with my picture?

    Sure, I am pretty good with Photoshop. I can email you, and have it done by the weekend for sure, maybe even tonight depending on how much you would like done. If you aren't satisfied with ...

  • Can you please go to my blog? i need hits?

    its ok, i left comments on some ideas i had...^.^

    ...
  • Just finished my c++ encryption program. Anyone want to check my code?

    (1) ifstream KeyRead; KeyRead.open(EncrKey); if(!KeyRead.is_open()) { cerr << "File failed to open for read. Program ending." << endl; ...

  • Can a slideshow made in a vista work in a mac?

    The issue isn't actually whether the computer is running Windows XP, Vista or Mac OS X, but whether or not it has PowerPoint (or some compatible equivalent, like iWork or OpenOffice.org) insta...

  • Java Nested For Loops question?!?!?

    Here's my solution, it must have taken me 2 or 3 hours. This is a tough one, I think. When my mind got boggled with nested loops and complex logic, I broke things apart into separate methods...

  •  

    Categories--Copyright/IP Policy--Contact Webmaster