Mail Archives: djgpp/1997/09/23/07:20:32
On Tue, 23 Sep 1997, GRANULAB international B.V. wrote:
> char *dumtxt[10];
> tijd abs;
> int c_edit=0x07, c_normal=0x05;
> ...
> ...
> sprintf(*dumtxt,"%02d:%02d:%02d",abs.uur,abs.minuut,abs.seconde);
> GrTextXY(GrMaxX()/2-25,25,*dumtxt,c_edit,c_normal);
If this fragment doesn't leave out anything important, then the problem
is that you pass `sprintf' a pointer that points to a random location:
you haven't initialized dumtxt[] with any valid addresses, so they
contain garbage.
You probably wanted to say this:
char dumtxt[10]
...
sprintf(dumtxt,"%02d:%02d:%02d", ...
I.e., you wanted to print into dumptxt[] array. But your code
declares dumtxt[] to be an array of POINTERS, not array of CHARACTERS,
and prints to a buffer pointed to by dumtxt[0]; and dumtxt[0] was not
initialized with any address at all.
> My questions are, why does it not crash in a dos-box (win95)
Because Windows 95 does a lousy job of disallowing illegal accesses to
memory. When you run in plain DOS, your DPMI host is CWSDPMI, and it
catches such illegal memory accesses and crashes your program.
For more info on this, read section 9.1 of the DJGPP FAQ list
(available as v2/faq210b.zip from the same place you get DJGPP).
- Raw text -