473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

array of array of complex things


I'm looking for an equivalent approach to what I would do in C++ such
to create a vector of vector of complex. I would do :

typedef std::vector < std::complex < double complex_dvec;
typedef std::vector < complex_dvec twod_complex_vec;

int main() {
twod_complex_vec tdv ( 3, 3 );
for ( size_t idx ( 0 ); idx < tdv.size(); ++idx )
{
for ( size_t jdx ( 0 ); jdx < tdv.front().size(); ++jdx )
tdv [ idx ] [ jdx ] = idx * jdx ;
}
}

I'm trying to come up with an equivalent C approach to this but I'm
going around in circles. Source snippet appreaciated.. Thanks in
advance for

Aug 29 '06 #1
2 1703
ma******@gmail.com wrote:
I'm looking for an equivalent approach to what I would do in C++ such
to create a vector of vector of complex. I would do :

typedef std::vector < std::complex < double complex_dvec;
typedef std::vector < complex_dvec twod_complex_vec;

int main() {
twod_complex_vec tdv ( 3, 3 );
for ( size_t idx ( 0 ); idx < tdv.size(); ++idx )
{
for ( size_t jdx ( 0 ); jdx < tdv.front().size(); ++jdx )
tdv [ idx ] [ jdx ] = idx * jdx ;
}
}

I'm trying to come up with an equivalent C approach to this but I'm
going around in circles. Source snippet appreaciated.. Thanks in
advance for
http://www.c-faq.com/aryptr/dynmuldimary.html
Aug 29 '06 #2
ma******@gmail.com wrote:
I'm looking for an equivalent approach to what I would do in C++ such
to create a vector of vector of complex. I would do :
Assuming C89 with no complex types:

struct complex {
double r,i;
};

struct vector {
void *data;
size_t size;
};

struct vector a;

a.data = malloc(NUM_VEC);
if (a.data == NULL)
handle_error();

a.size = NUM_VEC;
a.data[0] = create_complex_vector();
.....
push_value ( 3.4, -1, a.data[0]);

You'll obviously want to have the ability
to reallocate space as the vector grows, and
you'll want a more generic "constructor"
than create_complex_vector, but the
above demonstrates some ideas. You
wouldn't want to call malloc directly on
a.data, for example. Instead, you'll
want to write a function that takes perhaps
an initial size and an allocator function ptr
as parameters which will create the vector
for you. You might want to make the vector
an opaque type and hide the size_t variable
from the user....lots of ways to do this.

Aug 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: seia0106 | last post by:
Hello, Writing a program in c++ that should use complex numbers I have two choices before me. 1- define a struct for complex data i.e struct {float real,imag; }ComplexNum; 2-use an array...
25
by: CodeCracker | last post by:
Problem details below: I have few items(simple values or objects) to be put into an array and I implement it through a set rather than just an array of items. This is because every time I get a...
13
by: Mike P | last post by:
I have, what should be, a simple scope problem. Can you help me fix this? I'm trying to end up like this: originalArray = and newArray = . Instead I wind up like this: originalArray = and...
11
by: x-pander | last post by:
given the code: <file: c.c> typedef int quad_t; void w0(int *r, const quad_t *p) { *r = (*p); }
7
by: Adam Suszeck | last post by:
I have an application that has a state class, which basically stores application information for other forms to access during the execution of the application. In state, I store an array which...
2
by: jccorreu | last post by:
I'm taking in data from multiple files that represents complex numbers for charateristics of different elements. I begin with arrays of doubles and interpolate to get standard values in real and...
4
by: Andi | last post by:
Hi, I want to define the following functions before main(); I work with 2D arrays (fftw_complex) wich are arrays with array is real and array the imaginary part of a complex number. Now I want to...
5
by: bearophileHUGS | last post by:
For array.array "B" means unsigned char, and such arrays accept to be initialized from (str) strings too, this is quite useful: But it seems such capability isn't shared with the append: ...
2
by: Garg | last post by:
Hi All, I am facing one problem if you are having any solution please tell me. I have to pass an array from javascript to servlet. for this i created one array and pass that through submitting...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.