Out putting 2d arrays to text files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sjaco
    New Member
    • Oct 2006
    • 1

    Out putting 2d arrays to text files

    i need an application that output a list of data to a text file. i have it set to save all of the data into arrays but it will not output the arrays to a .txt file. All i get is 0x22fed0 in the txt. How do i get it to output the entire array?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Post your code

    Comment

    • dtimes6
      New Member
      • Oct 2006
      • 73

      #3
      What u get is the address to the array. do iterate it using a for loop.

      Comment

      • Starasoris
        New Member
        • Oct 2006
        • 11

        #4
        Originally posted by dtimes6
        What u get is the address to the array. do iterate it using a for loop.
        What type of data is the array. char? int? The array variable itself is nothing bat a pointer to that specified type.

        int Slab[50]

        Slab[20] = 100;
        Slab[20] will give the value 100 and it is an integer

        I will let you work the rest out.

        I must admit that this has the feel of an unstudied university assignment about it.
        There are far to many unqualified programmers with university degrees ;)

        Study hard.

        Comment

        • dtimes6
          New Member
          • Oct 2006
          • 73

          #5
          Originally posted by Starasoris
          What type of data is the array. char? int? The array variable itself is nothing bat a pointer to that specified type.

          int Slab[50]

          Slab[20] = 100;
          Slab[20] will give the value 100 and it is an integer

          I will let you work the rest out.

          I must admit that this has the feel of an unstudied university assignment about it.
          There are far to many unqualified programmers with university degrees ;)

          Study hard.
          array is not eq to pointer!

          Comment

          • dtimes6
            New Member
            • Oct 2006
            • 73

            #6
            See Peter van der Linden, Expert C Programming. for more details.

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              Originally posted by dtimes6
              array is not eq to pointer!
              No, but in a lot of situations they can be treated in the same mannor and I think this is one of them.

              Code:
              int *pointer = new int[50];
              int array[50];
              
              /* This is all valid */
              
              pointer[20] = 100;
              array[20] = 100;
              
              *(p+21) = 101;
              *(array+21) = 101;
              
              /* but */
              
              if (sizeof pointer != sizeof array) // This is true
              {
                  cout << "Size of pointer and array are different!" << endl;
              }
              
              /* and interestingly */
              
                  delete[] pointer;
                  pointer = array;
              
                  if (p == array) // This is true
                  {
                      cout << "p == array\n";
                  }
              
                  if (&pointer != &array)  // This is true but in fact wont compile in C++ 
                                           // because &pointer and &array have different types
                  {
                      cout << "&p != &array\n";
                  }

              Comment

              Working...