ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/23/08:00:34

From: raynee AT my-deja DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: GPF caused by string functions...
Date: Sat, 23 Sep 2000 11:35:18 GMT
Organization: Deja.com - Before you buy.
Lines: 51
Message-ID: <8qi4hm$ism$1@nnrp1.deja.com>
NNTP-Posting-Host: 195.92.194.42
X-Article-Creation-Date: Sat Sep 23 11:35:18 2000 GMT
X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
X-Http-Proxy: 1.1 www-cache.pol.co.uk (NetCache 4.1R5D2), 1.1 x73.deja.com:80 (Squid/1.1.22) for client 62.136.92.206, 195.92.194.42
X-MyDeja-Info: XMYDJUIDraynee
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I am trying to get some string functions to work as part of the
interface for my program. I am using ScreenPutString to write to the
screen and my code appears to work when I call my centrestring()
function once it works okay. A second call, however, causes a General
Protection fault no matter how I specify my parameters. The code that I
am using is:

/* Include standard DJGPP libraries */
#include <pc.h>
#include <conio.h>
#include <string.h>

/*  putstring ( str, fg, bg, col, row )
    Calls the DJGPP function ScreenPutString from libc.a */
int putstring ( char *str, int fg, int bg, int col, int row ) {
    ScreenPutString(str, (bg<<4) | fg, col, row);
}

/*  centrestring ( str, fg, bg, row, col, width )
    Writes the specified string to the screen, centring it as it does */
int centrestring ( char *str, int fg, int bg, int col, int row, int
width ) {
    char buf[81], spacer[81];
    int i,j,k;
    i = strlen(str);
    j = (width - i) / 2;
    memset(buf,' ',--j);
    strcat(buf,str);
    memset(spacer,' ',(width-i-j));
    strcat(buf,spacer);
    buf[width] = 0;
    putstring(buf,fg,bg,col,row);
}

/*  main
    Tests the code */
int main ( void ) {
    centrestring("Just one line is okay",WHITE,BLUE,0,0,80);
    centrestring("This should work.",WHITE,BLUE,0,1,80);
}

If anyone has any ideas as to why this doesn't work I would appreciate
any feedback.

Regards,

Ed


Sent via Deja.com http://www.deja.com/
Before you buy.

- Raw text -


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