Question:
hey plz chk out tis code i m gettin the segmentation fault erroe i m using gcc as the compiler..?
Akhil T
2007-07-24 23:12:21 UTC
#include
#include

main()
{

int i,j,k;
double a[4][4][4];
getvalues(&a[4][4][4]);


for(k=0;k<4;k++)
{
for(j=0;j<4;j++)
{
for(i=0;i<4;i++)
{
printf(" %lf ",a[i][j][k]);
}
}
}
return(0);
}

getvalues(double ***px)
{
int i,j,k;
for(j=0;j<4;j++)
{
for(i=0;i<4;i++)
{
for(k=0;k<4;k++)
{
*((*((*(px+i))+j))+k)=1;
}
}
}
return(0);
}



if u thnk there is ny error in this code plz inform me ....
but plz reply fast
Three answers:
ddsa
2007-07-25 01:36:13 UTC
basically, the problem is with how you have defined the function (getvalues)



just because you have a 3-dim array and then you pass a value into getvalues, you don't have to define the parameter as ***px. *px is what is needed



so if you change that you will stop getting the segmentation fault error. however, you may want to explain what you intend to achieve out of this code, so that a more appropriate check can be made to see if your code will work to acheive that



hope this helps.



p.s. if you are student, you should think about the issue rather than a solution. that will help you greatly.
2007-07-25 00:03:17 UTC
Try getvalues(&a)

There are better websites for getting homework help , check http://getafreelnacer.com/
cruppstahl
2007-07-25 02:56:50 UTC
when you using gcc, compile with the switch -g for debugging information:



gcc -g test.c



now start the binary (a.out) in a debugger

gdb a.out



type "r" to run the program. it will stop when it crashes; then look at the stack trace with "bt". it will show which line of your program causes the segmentation fault.



you can look "p" to look at the value of variables, i.e. "p i" prints the value of "i".


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...