home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- #include "useful.hpp"
-
- // Useful Functions
-
- // Character string based functions
-
- void rtrim(char *string)
- {
- register int i;
- if(!string) return;
- i = strlen(string);
- i--;
- while(string[i] == ' ')
- {
- string[i] = NULL;
- i--;
- }
- }
-
- void ltrim(char *string)
- {
- char *tmpptr;
- if(!string) return;
- tmpptr = string;
- while(*tmpptr == ' ') tmpptr++;
- strcpy(string, tmpptr);
- }
-
- void alltrim(char *string)
- {
- rtrim(string);
- ltrim(string);
- }
-
- char *center(char *string)
- {
- register int i;
- int length, spaces, newlen;
- char *tmpptr;
- length = strlen(string);
- if (length < 1 || length > 80)
- {
- return NULL;
- }
- spaces = 40 - (length / 2);
- newlen = spaces + length;
- tmpptr = new char[newlen + 1];
- for(i=0; i < newlen + 1; ++i) tmpptr[i] = NULL;
- for(i=0; i < spaces; ++i) strcat(tmpptr," ");
- strcat(tmpptr, string);
- return tmpptr;
- }
-
- char *center(char *string, int width)
- {
- register int i;
- int length, spaces, newlen;
- char *tmpptr;
- length = strlen(string);
- if (length < 1 || length > width)
- {
- return NULL;
- }
- spaces = (width / 2) - (length / 2);
- newlen = spaces + length;
- tmpptr = new char[newlen + 1];
- for(i=0; i < newlen + 1; ++i) tmpptr[i] = NULL;
- for(i=0; i < spaces; ++i) strcat(tmpptr," ");
- strcat(tmpptr, string);
- return tmpptr;
- }
-
- // Other functions
-
- void pause()
- {
- while(!kbhit());
- getche();
- if(kbhit()) getche();
- }
-
- int verify(char *yeschars, char *nochars)
- {
- int x,y;
- char ch, *tmpch;
- x = wherex();
- y = wherey();
- while(1)
- {
- gotoxy(x,y);
- ch = getchar();
- tmpch = yeschars;
- while(*tmpch)
- {
- if (*tmpch == ch) return 1;
- ++tmpch;
- }
- tmpch = nochars;
- while(*tmpch)
- {
- if (*tmpch == ch) return 0;
- ++tmpch;
- }
- }
- }
-
- int is_in(char ch,
- char *str)
- {
- while (*str)
- {
- if (*str == ch) return 1;
- str++;
- }
- return 0;
- }
-