C (191/257)

From:
Date:20 Feb 2001 at 16:48:04
Subject:includes and stuff

Hello,

I'm trying to make some functions for myself to make programming easier, i
want to put them in a seperate .h and .c file but i don't know how to
organize it.

I'll give an example:

i want to make a unit with my functions called myfunctions. So i start with
a header file:
#ifndef MYFUNCTIONS
#define MYFUNCTIONS

/* my function to get a filename using the asl.library */
char* getFilename(char* title, char* location)

//input a title that the asl will have, location is the place the where the
asl will start
//output a string with the given path and filename, will be empty is the
user-cancelled

#endif

So that's the header file, but then i did some thinking and had some
questions: the function needs the asl.library and the asl.h to work
properly. But when you need to open a libary you also need the Exec.h files
included. My question where to put those?
And should i really open those libraries in my function or should it be a
request before you use the function itself?

Then i started writing the myfunctions.c,
i wrote it, i'll give you the source for it (hasn't been tested, some maybe
lot's of bugs, just for the idea)

#include <string.h>
char* getFilename(char* title,char* location)
{
struct Library *AslBase;
struct FileRequester *fr;

if (AslBase = OpenLibrary("asl.library", 37L))
{
if (fr = (struct FileRequester *)
AllocAslRequest(ASL_FileRequest,
ASLFR_TitleText,
titel,
ASLFR_InitialDrawer,
home,
TAG_DONE))
{
if (AslRequest(fr, NULL))
{
printf("PATH=%s FILE=%s\n", fr->rf_Dir, fr->rf_File);
return(strcat(fr->rf_Dir,fr->rf_File));
}
FreeAslRequest(fr);
}
else return "";

CloseLibrary(AslBase);
}

}

So i found out, i needed the string.h include to be able to use the strcat
function, again i don't know what to do: put a #include <string.h> in this
myfunctions.c file, or should it be in my myfunctions.h file...

Maybe you don't get all my problems, but the mainpoint is: how to organize
such things to put some things in seperate files. Till this time i always
just one file with all the code scrammed into it, and i want to start
reorganizing my code.

Thanks for any help and for all people who reacted to my IDCMP question.



Groeten,

Joris Kempen - webmaster
visit www.detrekkers.com

I like work ... I can sit and watch it for hours.

------------------------ Yahoo! Groups Sponsor ---------------------~-~>
eGroups is now Yahoo! Groups
Click here for more details
http://click.egroups.com/1/11231/0/_/451227/_/982689856/
---------------------------------------------------------------------_->