.: FUNCTIONS :.

 
 

Functions


char *_strndup(char *str, int n);

Very useful to duplicate only a part of a string, returning a zero-terminated string

I don't know why, but there is no such function in the standard C library for win32, or I never found it


char *get_good_file(char *av_zero, char *file);

I think, one of the function I use the most, you give the argv[0] as first argument, and a name of a file to retrieve in the same directory as argv[0] (the program location)

On UNIX you only need to use ./file to retrieve the file, but on win32, the shell and the environment is not managed very well for that, so get_good_file() will help you perfectly for that

Be careful, it return an allocated pointer to char


char *get_next_line(int fd);

get_next_line is a very useful function to acquire input data, I already noticed problems with scanf that act weirdly when you enter a sentence for an integer value, and i dislike to use gets or function like that...

I always use it with file descriptor 0, to read the keyboard, like that, str = get_next_line(0); will read the keyboard until you strike the enter key, and then return the complete string into str


char *get_next_line_ex(FILE *fd);

This one act exactly the same as get_next_line, but read on a FILE* file descriptor, so it's to read a file, line by line, it's very very useful and it's the function I use more

for example :

char *str;
FILE *fd;
 
fd = fopen(file, "rb");
while ((str = get_next_line_ex(fd)))
{
  // things to do with str, exemple : printf("%s\n", str);
 
  free(str);
}

I always use this to read configuration file, and since they are often in the program root directory, it's easy to get it with get_good_file()


char **str_to_word_tab(char *sep, char *str);

This function is also very very useful for the configuration files, you give it a suit of separator and a string to cut, and it return an array of char*, containing all the strings cut by the separator, this function cut only outside the guillemets (" ")

for example, you have a configuration file containing "option = truc, chose, bidule", you can cut like that : tab = str_to_word_tab(",=", str); and tab[0] will contain "option", like that you'll be able to control if you are actually parsing options, and if yes (strcmp) then you just have to read tab[1], tab[2], tab[3] and so on to have every options


char **str_to_word_tab_original(char *sep, char *str);

It works exactly like str_to_word_tab, just above, but it doesn't mind the guillemets (" ")


void free_tab(char **tab);

This function is a cousin of str_to_word_tab*, it just free correctly a tab allocated by these functions


char *trim(char *str, char *inib);

The trim function will remove every undesired characters, and the beginning and the end of the string, the undesired characters are set via inib parameter

The function return exactly the same pointer as str, the function do not allocate any memory, it just move bytes into str buffer


term.c contains 3 functions :

void gotoxy(int x, int y);

This function allow you to set the current console terminal cursor

void set_color(int r, int g, int b, int intensity);

This one allow you to change the current console terminal foreground color, like that, you can write in red, blue, green or else, you just have to write 1 to set the color, or 0 to not set it, you can compound colors and the intensity flag is used to create clear color (1) or dark color (0)

void restore_default_color();

It restore the default color of the terminal (grey clear)

 
 

webmaster : sebseb@securesphere.net

.: HOME :.

 - Home

 - Old News

 

.: PROGRAMS :.

 - Graphic (10)

 - Network (7)

 - Games (2)

 - System (13)

 - Crypto (3)

 - Misc (3)

 - Game Programming Section

 - SCM Section

 

.: TUTORIALS :.

 - No tutorials yet

 

.: MISC :.


CrocoLib

CrocoSkinner
 

.: AUTHOR :.

 - My Curriculum-Vitae
 

.: LINKS :.

 - OpenGL

 - GameDev

 - SecureSphere

 - Warcraft3 FuckerFou

 - CaraibesSunshine

 - Ambria