This is a discussion on arrays within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by john5754 Here is what I got, It seems to work when I run it. See any problems? ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Quote Originally Posted by john5754
    Here is what I got, It seems to work when I run it. See any problems?
    It should not even compile without errors since this statement is not terminated by a semi-colon:
    int jimmy[Height * Width]
    I suggest that you post your actual code (copy and paste, if necessary), and please post it in [code][/code] bbcode tags.

    Incidentally, I think that you need two arrays: the two dimensional array source and the one dimensional array destination. Alternatively, you use a one dimensional array and access it as a two dimensional array (but that seems the opposite of what you are asking for). Or, you use a two dimensional array and access it as a one dimensional array via a cast (but in practice, this should be avoided).
    Last edited by laserlight; 12-01-2008 at 10:14 AM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Nov 2008
    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main()
    	const int j=99;
    	int height=3,width=5,n,m,i,jimmy[j];
    	for(n=0; n<height; n++)
    		for(m=0; m<width; m++)
    		{jimmy [n]=(n+1)*(m+1);
    		cout<< setw(4)<< jimmy[n];
    	return 0;

  3. #18
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    I really don't get what you're trying to accomplish here. The code you've posted does nothing but assign some random values to the first three elements in a one-dimensional array. If you want to transform a 2-d array to 1-d, just do a cast. If you want to copy it then do the cast and use memcpy (height * width * sizeof( int )). Or, if you insist on doing it the hard way, source[ n ][ m ] == destination[ width * n + m ].
    bool fun(bool value)
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 06:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 03:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 09:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 08:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21