473,657 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multidimentiona l array problem.

2 New Member
Dear All

I have the following code which gives a segmentation fault. I dont think the array size is too large to result in a segmentation fault. Any help please.

Expand|Select|Wrap|Line Numbers
  1. int xdim = 36;
  2. int ydim = 256;
  3. int zdim = 256;
  4.  
  5. double ***something = (double ***)malloc(xdim * sizeof(double **));
  6. for(i=0; i< xdim; i++)
  7. something[i] = (double **)malloc(ydim * sizeof(double *));
  8.  
  9. for(j=0; j< ydim; j++)
  10. something[i][j] = (double *)malloc(zdim * sizeof(double));
  11.  
  12. for(i=0; i< xdim; i++)
  13. for(j=0; j< ydim; j++)
  14. for(k=0; k< zdim; k++)
  15. something[i][j][k] = 1.0;
  16.  
Thanks in advance,
Prasad.
Aug 21 '07 #1
3 1363
hariharanmca
1,977 Top Contributor
Dear All

I have the following code which gives a segmentation fault. I dont think the array size is too large to result in a segmentation fault. Any help please.

Expand|Select|Wrap|Line Numbers
  1. int xdim = 36;
  2. int ydim = 256;
  3. int zdim = 256;
  4.  
  5. double ***something = (double ***)malloc(xdim * sizeof(double **));
  6. for(i=0; i< xdim; i++)
  7. something[i] = (double **)malloc(ydim * sizeof(double *));
  8.  
  9. for(j=0; j< ydim; j++)
  10. something[i][j] = (double *)malloc(zdim * sizeof(double));
  11.  
  12. for(i=0; i< xdim; i++)
  13. for(j=0; j< ydim; j++)
  14. for(k=0; k< zdim; k++)
  15. something[i][j][k] = 1.0;
  16.  
Thanks in advance,
Prasad.
Hi just check here.

for(i=0; i< xdim; i++)
something[i] = (double **)malloc(ydim * sizeof(double *));
// after this for loop i = xdim
for(j=0; j< ydim; j++)
//something[i][j] will be something[xdim][0 to ydim]
something[i][j] = (double *)malloc(zdim * sizeof(double)) ;

and point what error you are getting.
Aug 21 '07 #2
pessi
2 New Member
After seeing your reply I realised what a fool I am. The problem is that every problem scares me before even I attempt at it...damn..that was very easy...thanks anyway

Thank you again.
prasad.
Aug 21 '07 #3
hariharanmca
1,977 Top Contributor
After seeing your reply I realised what a fool I am. The problem is that every problem scares me before even I attempt at it...damn..that was very easy...thanks anyway

Thank you again.
prasad.


Happy Coding and take care.
Aug 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
3255
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) CType(local4, Short) = CType(src, Short)
9
4791
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I am using vector class(STL), the compiler does not allow me to do this. I do realize there is a pitfall in this approach(size of arrays not matching etc), but I wonder how to get around this problem. I have a class hierachy with abstract base...
7
4139
by: Bangalore | last post by:
Hi all, Plz clarify me, on the implementation of two or three dimensional array using overloaded operator. Thanks, in advance Bangalore
5
2204
by: ritchie | last post by:
Hi, I am writing to ask if anyone can see why my array is not being sorted correctly? It's an array of 4 elements(ints 1,2,3,4) but after calling the selection sort it comes back sorted as 1,1,2,4. I have narrowed it down to the sort function. I'm almost positive
8
4605
by: Gerald | last post by:
I have a problem with an array of pointers. In a program I'm writing, I have to read a file, containing thousands of short lines. The content of another file will be compared against each line later on. Before that happens there has been a problem that causes a crash of the program. This is a little program "test.exe" I wrote to test what happens. compiler: mingw 3.1.01 for win32 command line
12
5502
by: arkobose | last post by:
my earlier post titled: "How to input strings of any lengths into arrays of type: char *array ?" seems to have created a confusion. therefore i paraphrase my problem below. consider the following program: #include<stdio.h> #define SIZE 1 int main()
23
7395
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
1
1199
by: unnii | last post by:
Hi All, am new to php and to this forum... Pls help me to get more idea on php. Input File: "EmpDet.txt" whic contains: Id:1,Name:Unni,DOB:31/12/80 Address_1:A1,Address_2=A2 Phone_1:98869898,Phone_2:8978090
4
2646
by: student4lifer | last post by:
If I have a multidimentional array that contains many arrays inside as follows: $voters=array(array('name'=>'Joe', 'profession'=>'blumbing', 'state'=>'Ohio'), array('name'=>'Obama', 'profession'=>'senator', 'state'=>'Ilinois'), array('name'=>'Palin', 'profession'=>'moose hunter', 'state'=>'Alaska'), .. ..
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7321
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.