cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/12/03:04:48

Message-ID: <000d01be565c$6a6c1240$c510f2d4@jakob>
From: "Jakob Diness" <diness AT person DOT dk>
To: <djgpp AT delorie DOT com>
Subject: C - problems
Date: Fri, 12 Feb 1999 08:50:19 +0100
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Reply-To: djgpp AT delorie DOT com

This is a multi-part message in MIME format.

------=_NextPart_000_000B_01BE5664.B8066DE0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Okay, I spend quite a few hours reading the FAQ-sections and found out =
lots of things, but my main problem still exists.

I have installed the v2 package og DJGPP, and small trivial programs =
like "Hello world" works.

Now, I need to run a bigger program, which works on other machines (eg =
code correct, my teacher made it).
Probably I need help.=20

I compile and build the program even with the -Wall command, but NOTHING =
works. Probably I do not point to the libraries correct ??, I never =
programmed before, my vocab. expanded quite a bit the last few days.


Short version :
My program consists of the 3 lib-references

#include <stdio.h>=20
#include <stdlib.h>
#include <math.h>=20

and I write and get :

Microsoft(R) Windows 95
   (C)Copyright Microsoft Corp 1981-1995.

C:\dokumenter\mat=F8k\nummetoder>gcc -c kap1jh.c

C:\dokumenter\mat=F8k\nummetoder>gcc -o kap1jh.exe kap1jh.c

C:\dokumenter\mat=F8k\nummetoder>kap1jh.exe
Exiting due to signal SIGSEGV
Stack Fault at eip=3D000019ad
eax=3D00000001 ebx=3D000082b3 ecx=3D000004b0 edx=3D0000d644 =
esi=3D00000054 edi=3D00023d70
ebp=3D000a3d50 esp=3Dfffb955c =
program=3DC:\DOKUME~1\MAT=D8K\NUMMET~1\KAP1JH.EXE
cs: sel=3D00a7  base=3D82b38000  limit=3D000affff
ds: sel=3D00af  base=3D82b38000  limit=3D000affff
es: sel=3D00af  base=3D82b38000  limit=3D000affff
fs: sel=3D0087  base=3D00012bc0  limit=3D0000ffff
gs: sel=3D00bf  base=3D00000000  limit=3D0010ffff
ss: sel=3D00af  base=3D82b38000  limit=3D000affff
App stack: [000a3d70..00023d70]  Exceptn stack: [00023c58..00021d18]

Call frame traceback EIPs:
  0x000019ad
ss: sel=3D0243  invalid
App stack: [00aef000..00a6f000]  Exceptn stack: [00023c58..00021d18]

Call frame traceback EIPs:
  0x00002f31

C:\dokumenter\mat=F8k\nummetoder>gcc -Wall -o kap1jh.exe kap1jh.c
kap1jh.c: In function `printsol':
kap1jh.c:97: warning: use of `l' length character with `f' type =
character
kap1jh.c:99: warning: use of `l' length character with `f' type =
character
kap1jh.c:99: warning: use of `l' length character with `e' type =
character
kap1jh.c:99: warning: use of `l' length character with `e' type =
character
kap1jh.c:99: warning: use of `l' length character with `e' type =
character
kap1jh.c: At top level:
kap1jh.c:105: warning: return-type defaults to `int'
kap1jh.c: In function `main':
kap1jh.c:113: warning: use of `l' length character with `f' type =
character
kap1jh.c:113: warning: use of `l' length character with `f' type =
character
kap1jh.c:113: warning: use of `l' length character with `f' type =
character
kap1jh.c:116: warning: use of `l' length character with `e' type =
character
kap1jh.c:116: warning: use of `l' length character with `e' type =
character
kap1jh.c:106: warning: unused variable `printcount'
kap1jh.c:143: warning: control reaches end of non-void function


-------

I do not expect you to have time to read through all this, but anyway - =
I attach the files for the whole program.

Any suggestions welcomed. Pls. send to me direct, because I do not know =
how to acces the news-group


------=_NextPart_000_000B_01BE5664.B8066DE0
Content-Type: application/octet-stream;
	name="jh.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="jh.c"

/* File: jhu/undervisning/fdm99/ibvp1.c
   compile with the command:  cc ibvp1.c -lm
   run with the command:      a.out           */

#include <stdio.h>=20
#include <stdlib.h>
#include <math.h>=20

/* ***********************************************************
   Program for the solution of initial-boundary-value problems
   of the form

   v (x,t) + r*v (x,t) =3D s*v (x,t) + F(x,t)  x0<x<x1, 0<t
    t           x           xx

   v(x,0) =3D f(x)  x0<=3Dx<=3Dx1

   bdrcond1 =3D L v(x0,t) =3D a(t)  t>=3D0
               1

   bdrcond2 =3D L v(x1,t) =3D b(t)  t>=3D0
               2

   Solution method: Explicit finite difference method, forward in time =
(FT),
                    arbitrary in space, uniform mesh (subdivision).=20

   xk =3D x0 + k*Dx, k=3D0,...,M, Dx =3D (x1-x0)/M

   tn =3D n*Dt, n=3D0,...,N, Dt =3D tend/N

   Input: x0,x1,M,tend,N,printtimes

   Subroutines: r,s,F,f,a,b
 =20
   *********************************************************** */

/* global variables*/

double uold[10000]; =20
int printcount=3D0;

/* External functions */

double f(double x){double pi=3D3.14159265358979323846; =
return(sin((double)2*pi*x));}

double r(void){return(0.0);}

double s(void){return((double)1/6);}

double F(double x,double t){return(0.0);}

double vx(int k,double delx){return((uold[k+1]-uold[k-1])/(2.0*delx));}

double vxx(int k,double =
delx){return((uold[k-1]-2.0*uold[k]+uold[k+1])/(delx*delx));}

double bdrcond1(double delx,int n,double delt){return(0.0);}

double bdrcond2(double delx,int n,double delt){return(0.0);}

double uex(double x,double t){
  /* Exact solution for r=3DF=3D0, a=3Db=3D0, Dirichlet bdrcond. */
  double pi=3D3.14159265358979323846; =
return(exp(-(double)4*s()*t*pi*pi)*sin((double)2*pi*x));}

void printsol(double Dx,int M,int n,double Dt,double x[],double t[],int =
nprint[])
{
  int k;
  if(n=3D=3Dnprint[printcount]){ /* check if we need to print =
initially*/
    printcount+=3D1;
    printf("**** t=3D%lf****\n",n*Dt);
    for(k=3D0;k<=3DM;++k) printf("  x=3D%12.5lf,  ufd=3D%12.5le, =
uex=3D%12.5le, =
uex-ufd=3D%12.5le\n",k*Dx,uold[k],uex(x[k],t[n]),uex(x[k],t[n])-uold[k]);=

    printf("****************\n\n");
  }
}  =20

main(){

  int M,N,numprint,nprint[100],i,printcount,k,n;
  double x0,x1,tend,Dx,Dt,x[10000],t[100000],unew[10000];

  printf("x interval [x0,x1],  Number of x-subintervals M\n"); =20
  printf("t interval [0,tend], Number of t-subintervals N\n");
  printf("Input x0 x1 M tend N =3D=3D> ");
  scanf("%lf%lf%d%lf%d",&x0,&x1,&M,&tend,&N);
  printf("x0 =3D %.1lf, x1 =3D %.1lf, M =3D %d, tend =3D %.1lf, N =3D =
%d\n",x0,x1,M,tend,N);
  Dx=3D(x1-x0)/M;
  Dt=3Dtend/N;
  printf("Dx=3D%.3le, Dt=3D%.3le\n",Dx,Dt);
  printf("Input number of print times =3D=3D> ");
  scanf("%d",&numprint);
  printf("Input time steps n1...n%d, where printing is done =3D=3D> ", =
numprint);
  for(i=3D0;i<numprint;++i)scanf("%d",&nprint[i]);
  nprint[numprint]=3DN+1; /* To not owerflow if we do not print the last =
time step */
  /* For testing:
     printf("Print time steps:\n");
     for(i=3D0;i<numprint+1;++i)printf("%d\n",nprint[i]); */
  for(k=3D0;k<=3DM;++k) x[k]=3Dk*Dx; /* Space subdivision */
  for(n=3D0;n<=3DN;++n) t[n]=3Dn*Dt; /* Time subdivision */
  for(k=3D0;k<=3DM;++k) uold[k]=3Df(x[k]); /* Initialize solution with =
initial data */
  printsol(Dx,M,0,Dt,x,t,nprint); /* print initially, if required */
  for(n=3D1;n<=3DN;++n){ /* time stepping loop */
    for(k=3D1;k<M;++k){ /* space stepping loop */
      unew[k]=3Duold[k]+Dt*(-r()*vx(k,Dx)+s()*vxx(k,Dx)+F(x[k],t[n])); =
/* difference equation */
    }
    unew[0]=3Dbdrcond1(Dx,n,Dt); /* left boundary condition */
    unew[M]=3Dbdrcond2(Dx,n,Dt); /* right boundary condition */
    for(k=3D0;k<=3DM;++k) uold[k]=3Dunew[k]; /* update solution */
    printsol(Dx,M,n,Dt,x,t,nprint); /* print at time step n if required =
*/
/* tilf=F8jet ny linje */
} /* end of time stepping loop */
} /* end of main */
------=_NextPart_000_000B_01BE5664.B8066DE0--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019