hello, I'm trying to write a source in c, but I've a big problem. when i write my code
like this: -
#include <stdio.h>
-
#include "lfixo.h"
-
-
extern long int a,m;
-
extern float nad[7];
-
-
float Tgl0 = 580;
-
float Tr0 = 590;
-
-
void ci(float **Tgl,float **Ts,float **Tr)
-
{
-
Tgl = Alocar(a,m);Ts = Alocar(a,m);Tr = Alocar(a,m);
-
long int i,j,k;
-
-
for(j=0;j<m;j++)
-
{
-
// inicialização das temperaturas
-
-
Tgl[0][j]=Tgl0;
-
-
//condições iniciais de temperatura na fase fluida
-
Ts[0][j]=Tgl0; //condições iniciais de temperatura na fase sólida
-
Tr[0][j]=Tr0; //condições iniciais de temperatura na fluido refrigerante
-
-
-
Liberar(a,m,Tgl);Liberar(a,m,Ts);Liberar(a,m,Tr);}
-
-
-
where is Alocar and Liberar are function to alocate and release memory for may 2d matrix.
and the main function are: -
#include <stdio.h>
-
#include "lfixo.h"
-
long int a=2400,m=6;
-
float nad[7],dt;
-
-
void main(void)
-
-
{
-
float **Tgl, **Ts, **Tr;
-
-
ci(Tgl,Ts,Tr);
-
}
-
thus, my program works. but if put any change(considering the same main function) as the follow(The line 30 is the difference between 2 codes ): -
-
#include <stdio.h>
-
#include "lfixo.h"
-
-
extern long int a,m;
-
extern float nad[7];
-
-
float Tgl0 = 580;
-
float Tr0 = 590;
-
-
void ci(float **Tgl,float **Ts,float **Tr)
-
{
-
Tgl = Alocar(a,m);Ts = Alocar(a,m);Tr = Alocar(a,m);
-
long int i,j,k;
-
-
-
for(j=0;j<m;j++)
-
{
-
// inicialização das temperaturas
-
-
Tgl[0][j]=Tgl0;
-
-
//condições iniciais de temperatura na fase fluida
-
Ts[0][j]=Tgl0; //condições iniciais de temperatura na fase sólida
-
Tr[0][j]=Tr0; //condições iniciais de temperatura na fluido refrigerante
-
}
-
for(k=0;k<a;k++){
-
for (j=1;j<=m-1;j++) {
-
// nós internos
-
// the line below is cause of my problem Tgl[k+1][j]=Tgl[k][j]*(1-2*nad[1]-nad[2]-nad[3])+Tgl[k][j-1]*(nad[0]+nad[1])+Tgl[k][j+1]*(-nad[0]+nad[1])+nad[2]*Ts[k][j]+nad[3]*Tr[k][j];
-
-
}
-
}
-
-
Liberar(a,m,Tgl);Liberar(a,m,Ts);Liberar(a,m,Tr);}
-
my code doesn't work well, for example, if set a=240(in main function), the loop goes up to a=226. then if set a=226 the loop run until a=200(or something like this). and now what I have to do?what or where is the problem?
1 1150
void ci(float **Tgl,float **Ts,float **Tr) <<<<<<<<<<<<<<<<<<<<<
{
Tgl = Alocar(a,m);Ts = Alocar(a,m);Tr = Alocar(a,m);
long int i,j,k;
void main(void)
{
float **Tgl, **Ts, **Tr;
ci(Tgl,Ts,Tr); <<<<<<<<<<<<<<<<<<<<<<<
}
I'm not sure what you are doing here. ci() takes float** argiments. Your main() passes float** variables. The problem is that the Tgl, Ts and Tr in the function are copies of the Tgl, Ts and Tr variables used on the call. At the end of ci(), these copies will be destroyed. The net effect is nothing comes out of your function and the variables in main() never do get initialized. If main() continues, you will crash shortly.
Normally in a case like this, ou declare pointers in main() and pass the addresses to the function. The function now had the address of the pointer so it can dereference this address to update the address in the pointer used on the call. -
void MyFunction(float** arg)
-
{
-
*arg = malloc(sizeof(float));
-
}
-
-
int main()
-
{
-
float* result;
-
MyFunction(&result);
-
}
-
Maybe you can clear this up before I look at your other main().
Sign in to post your reply or Sign up for a free account.
Similar topics
by: I_have_nothing |
last post by:
Hi!
I am new in C. I got a lots of "Segmentation Fault"s in my code.
I guess One possibility is:
if " int array_i; " is declard and the code trys to access
"array_i",
a Segmentation Fault will...
|
by: Fra-it |
last post by:
Hi everybody,
I'm trying to make the following code running properly, but I can't get
rid of the "SEGMENTATION FAULT" error message when executing.
Reading some messages posted earlier, I...
|
by: Digital Puer |
last post by:
Hi, I'm coming over from Java to C++, so please bear with me.
In C++, is there a way for me to use exceptions to catch
segmentation faults (e.g. when I access a location off
the end of an array)?...
|
by: Paminu |
last post by:
I have a wierd problem.
In my main function I print "test" as the first thing. But if I run the call
to node_alloc AFTER the printf call I get a segmentation fault and test is
not printed!
...
|
by: madunix |
last post by:
My Server is suffering bad lag (High Utlization)
I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2
Web visitors retrieve data from the web by php calls through oci
cobnnection...
|
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,...
|
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,...
|
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...
|
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...
|
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: 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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| | |