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. txt file

txt file

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestutorialquestion
7 Posts 5 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

    How to write the output array to a text file?

    D H G T 4 Replies Last reply
    0
    • C chaitanya22

      How to write the output array to a text file?

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

      chaitanya22 wrote:

      How to write the output array...

      What output array?

      chaitanya22 wrote:

      How to write...to a text file?

      What text file?


      "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

      C 1 Reply Last reply
      0
      • C chaitanya22

        How to write the output array to a text file?

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

        for write to file you can use CArchive But please refer to Reply David Crow

        1 Reply Last reply
        0
        • C chaitanya22

          How to write the output array to a text file?

          G Offline
          G Offline
          gamitech
          wrote on last edited by
          #4

          if you meant the values of and array in a txt file you can use the binary files to write the whole array in it but binary mode. f=fopen(fname,"bw"); fwrite(array,1,sizeof(int)*nr_of_items,f); fclose(f); but if you want the values to be readable you must convert them first to chars and then write them. char nr[10]; /*if array declared like this int array[100] or int *array*/ f=fopen(fname,"w+"); for (int i=0;i nr_of_items line the entries or something like this. have fun gabby

          1 Reply Last reply
          0
          • C chaitanya22

            How to write the output array to a text file?

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            what about CFile;

            CFile a("C:\\tmp.txt",CFile::modeWrite|CFile::modeCreate);
            // Let m_arrString is you array and nSize its size
            for(int i=0;i

            1 Reply Last reply
            0
            • D David Crow

              chaitanya22 wrote:

              How to write the output array...

              What output array?

              chaitanya22 wrote:

              How to write...to a text file?

              What text file?


              "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

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

              its an int array[].

              D 1 Reply Last reply
              0
              • C chaitanya22

                its an int array[].

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

                Here's one way:

                FILE *pFile = fopen("file.txt", "w");
                for (int x = 0; x < sizeof(array) / sizeof(array[0]); x++)
                fprintf("%d\n", array[x]);
                fclose(pFile);

                Others exist, too.


                "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
                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