delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/27/20:49:32

Message-ID: <36AE2EF6.3AC3@seidata.com>
From: Marvin G Wise Jr <mgwise AT seidata DOT com>
Organization: WiseGuy Software
X-Mailer: Mozilla 3.01C-KIT (Win16; U)
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problem implementing multiple moduled program
References: <36b41be7 DOT 2525182 AT news>
Lines: 104
Date: Tue, 26 Jan 1999 13:09:10 -0800
NNTP-Posting-Host: 205.243.237.77
X-Trace: news.goodnet.com 917460355 205.243.237.77 (Wed, 27 Jan 1999 11:05:55 MDT)
NNTP-Posting-Date: Wed, 27 Jan 1999 11:05:55 MDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Stuart Hall wrote:
> 
> Good morning.  I asked once before how to make a multiple module
> program, and I got some answers but once again I am stuck.  I wish to
> implement a "getsafe" function that I can include in most of my
> programs - and I have attached my first attempt.
> 
> /* begin "getsafe.h" */
> 
>  char *getsafe(char *buffer, int count)
> 
> /* ---  */
> 

Well, if this is the function prototype in your header file then it
should have a semicolon at the end...

    char *getsafe(char *buffer, int count);


> Is there anything else I need in a header file?  DJGPP specific --
> what do I need to do with a .h file, just save-as, or do I need to
> compile it?
> 
> /* begin "main.c"  */
> 
> #include <stdio.h>
> #include <string.h>
> #include <stdlib.h>
> #include "getsafe.h"
> 
> /* char result[80]; */
> /* int result_num=sizeof(result);  */
> 
> int main(void)  /*  I get a "parse error before {"  */
> {
>  printf("Enter up to %d characters:  ",result_num-1);
>  getsafe(result, result_num);
>  printf("your string is %s",result);
>  return 0;
> }
> 
> /* -----   */
> 

It looks to me like the parse errors all go back to the missing
semicolon...of course i may be wrong but it's a good practice to fix one
error at a time as one error can cause a snowball effect....

> On the above program, I also tried defining result[80], and result_num
> in the body of main, in the body of my getsafe() module, and leaving
> it out.  Either way, the compiler would give me an error about
> 
> I did get an error when putting #include <getsafe.h> about a file not
> found, but as soon as I put it in quotes the error went away.
> 
> My errors:
> In function 'getsafe'
> main.c(7)  Parse error before '{'
> main.c(6)  Parm types given both in parm list and separately
> 
> /*  Begin Getsafe.c module  */
> 
> #include <stdio.h>
> #include <string.h>
> 
> char result[80];
> int result_num=sizeof(result);
> 
> char *getsafe(char *buffer, int count)
> {
>  char *result = buffer, *np;
>  if ((buffer==NULL) || (count <1))
>    result = NULL;
>  else if (count == 1)
>    *result = '\0';
>  else if ((result = fgets(buffer, count, stdin)) != NULL)
>    if ((np = strchr(buffer, '\n')))
>          *np = '\0';
>  return result;
> }
> 
> /*  -----  compiles without errors --- */
> 
> Any hints?  I am sure my program is riddled with errors, but after
> reading a few tutorials I can't quite figure it out.  It seems like I
> am missing a getsafe function prototype from my getsafe.h header file
> or from getsafe.c, but none of my examples had it.  Hmmmm.
> 
> Thanks in advance for your help.  BTW, when run as a singular program
> I have no problem implementing my getsafe function.
> 
> Stuart Hall
> 
> ----
> Stuart Hall
> Connecticut, USA
> * return address:  f p r i n t @ i n a m e . c o m *

If you're using a project file like in Rhide, you'll want to include
main.c and getsafe.c in that...other than the missing semicolon it all
looks good to me..

WG

- Raw text -


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