Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. conversion of Int to Char

conversion of Int to Char

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chaitanya22
    wrote on last edited by
    #1

    Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file. am using itoa(), but i couldne get the result. Can anybody could help me out?

    C H N C D 5 Replies Last reply
    0
    • C chaitanya22

      Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file. am using itoa(), but i couldne get the result. Can anybody could help me out?

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      I suppose you want to convert int values into strings (and not into a char value). What is the problem with itoa ? You could also use sprintf.

      C 1 Reply Last reply
      0
      • C chaitanya22

        Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file. am using itoa(), but i couldne get the result. Can anybody could help me out?

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        Hi chaitanya22, For save data in the file please studing CArchive

        1 Reply Last reply
        0
        • C chaitanya22

          Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file. am using itoa(), but i couldne get the result. Can anybody could help me out?

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #4

          You cannot convert the entire array at once using itoa. You have to pick out individual elements for conversion. For eg:

          #include "stdafx.h"
          #include "sstream"

          int main()
          {
          string strIntArray;
          stringstream sstr;
          int randomArray[10];

               //fill this array with random elements....
          for(int index=0;index<10;index++)
          {
          	randomArray\[index\] = rand()%10000;
          }
               //convert each element...
          for(int index=0;index<10;index++)
          {
          	sstr< 
          

          Nibu thomas
          Software Developer

          1 Reply Last reply
          0
          • C chaitanya22

            Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file. am using itoa(), but i couldne get the result. Can anybody could help me out?

            C Offline
            C Offline
            chetan210183
            wrote on last edited by
            #5

            hi, did u include stdlib.h where itoa() is described? Chetan. Helping others satisfies you...

            C 1 Reply Last reply
            0
            • C Cedric Moonen

              I suppose you want to convert int values into strings (and not into a char value). What is the problem with itoa ? You could also use sprintf.

              C Offline
              C Offline
              chaitanya22
              wrote on last edited by
              #6

              actually, i would like to load the int array data which is obtained from a machine to a txt file, i could open the text file, but i couldnt write the data i,e int array to text file, its writing some junk values. int array[100];//am having an int array char txt[100];//would like to convert the numbers in int array to string and should be stored in txt array. for(i=0;i<=100;i++) {itoa(array[i],txt,10); fwrite(txt,1,strlen(txt),f);//f=fopen("data.txt", "w+"); }

              1 Reply Last reply
              0
              • C chetan210183

                hi, did u include stdlib.h where itoa() is described? Chetan. Helping others satisfies you...

                C Offline
                C Offline
                chaitanya22
                wrote on last edited by
                #7

                ya, i have included

                C 1 Reply Last reply
                0
                • C chaitanya22

                  Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file. am using itoa(), but i couldne get the result. Can anybody could help me out?

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  chaitanya22 wrote:

                  Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file.

                  There is no need to convert just to save to a text file. Numbers can be written to the file just like characters can.


                  "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                  "There is no death, only a change of worlds." - Native American Proverb

                  1 Reply Last reply
                  0
                  • C chaitanya22

                    ya, i have included

                    C Offline
                    C Offline
                    chetan210183
                    wrote on last edited by
                    #9

                    Hi Chaitanya, Try out this. FILE *fp; fp = fopen("chat.txt","w"); int a[10] = {5,15,25,35,45,55,65,75,85,95}; char p[20]; for (int i = 0;i < 10; i++) { itoa(a[i],p,10); fprintf(fp,"%s ",p); } Chetan. Helping others satisfies you...

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups