?
Solved

Simple array conversion

Posted on 1998-08-26
3
Medium Priority
?
201 Views
Last Modified: 2010-04-15
Hi,

I have 3 2-d arrays and tried to convert them into 1-d array. The original arrays are a,b and c and the 1d arrays are a2,b2 and c2. My code segment:

k=0;
for (i=0, i<MAXI; i++)
     for (j=0; j<MAXY; j++)
          {
                a2[k++]=a[i][j];
                b2[k++]=b[i][j];
                c2[k++]=c[i][j];
           }

The output was incorrect and I can't figure out what causes the error. Please advise.
Thanks.
0
Comment
Question by:peiyoke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1252328
In what way was the output incorrect?

Did you want a ++ on all of those [k]s?
0
 
LVL 4

Accepted Solution

by:
sganta earned 30 total points
ID: 1252329
Hello !

You are incrementing k after every assignment, That is why you are o/p is incorrect.

It should be like this
k=0;
    for (i=0, i<MAXI; i++)
         for (j=0; j<MAXY; j++)
              {
                    a2[k]=a[i][j];
                    b2[k]=b[i][j];
                    c2[k]=c[i][j];
                    k++;
               }

OR

It can be like this
k=0;
    for (i=0, i<MAXI; i++)
         for (j=0; j<MAXY; j++)
              {
                    a2[k]=a[i][j];
                    b2[k]=b[i][j];
                    c2[k++]=c[i][j];
               }
0
 
LVL 3

Expert Comment

by:braveheart
ID: 1252330
You know that all those 2D arrays are really 1D arrays already. They are just in column order instead of row order. Do you really need to convert them, even though it is very simple to do.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question