| delorie.com/archives/browse.cgi | search |
| From: | "Morpheus" <hall AT silo DOT csci DOT unt DOT edu> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: make/linking trouble |
| Date: | Sun, 7 Nov 1999 19:33:42 -0600 |
| Organization: | Zion |
| Lines: | 70 |
| Message-ID: | <8059c5$ms6@hermes.acs.unt.edu> |
| References: | <80592o$mnp AT hermes DOT acs DOT unt DOT edu> |
| NNTP-Posting-Host: | dfw-premium-45.dialup.unt.edu |
| X-Priority: | 3 |
| X-MSMail-Priority: | Normal |
| X-Newsreader: | Microsoft Outlook Express 5.00.2314.1300 |
| X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2314.1300 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
*StringUtils.h*
#ifndef __STRING_UTILS__
#define __STRING_UTILS__
#define MAX_CHARS 255;
void freeString(char* str);
char** newStringArray(int n);
void freeStringArray(char** str);
char** resizeStringArray(char** str, int n);
char** newStringArrayFromFile(char* file);
#endif __STRING_UTILS__
*StringUtils.cpp*
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <fstream.h>
#include "FileUtils.h"
#include "StringUtils.h"
void freeString(char *str) {
if(str != NULL) {
delete str;
str = NULL;
}
}
char** newStringArray(int n) {
char** str = new char*[n];
for(int i = 0; i < (n - 1); i++) {
str[i] = "";
}
str[n - 1] = NULL;
return str;
}
void freeStringArray(char** str) {
if(str != NULL) {
for(int i = 0; str[i] != NULL; i++) {
freeString(str[i]);
}
str = NULL;
}
}
char** resizeStringArray(char** str, int n) {
char** strA = newStringArray(n);
for(int i = 0; i < n; i++) {
strA[i] = NULL;
}
if(str != NULL) {
for(int i = 0; i < n; i++) {
if(str[i] == NULL) {
break;
}
strA[i] = strdup(str[i]);
}
}
freeStringArray(str);
return strA;
}
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |