Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct {
- char *historyCommand;
- int usedSize;
- int maximumSize;
- } HistoryArray;
- void CreateHistoryArray(HistoryArray *HistoryArray) {
- HistoryArray->historyCommand = (char *) malloc(sizeof(char) * MAX_LEN);
- HistoryArray->usedSize = 0;
- HistoryArray->maximumSize = INITIAL_SIZE;
- }
- void ExpandHistoryArray(HistoryArray *HistoryArray, int newSize) {
- int *newArray = (char *) malloc(sizeof(char) * newSize);
- memcpy(newArray, HistoryArray->historyCommand, sizeof(char) * HistoryArray->maximumSize);
- free(HistoryArray->historyCommand);
- HistoryArray->historyCommand = newArray;
- HistoryArray->maximumSize = newSize;
- }
- void AddHistoryValue(HistoryArray *HistoryArray, char historyCommand[]) {
- strcpy(HistoryArray->historyCommand[HistoryArray->usedSize], historyCommand);
- HistoryArray->usedSize++;
- if (HistoryArray->usedSize == HistoryArray->maximumSize) {
- ExpandHistoryArray(HistoryArray, HistoryArray->maximumSize * 2);
- }
- }
- void freeHistoryArray(HistoryArray *a) {
- free(a->historyCommand);
- a->historyCommand = NULL;
- a->usedSize = 0;
- a->maximumSize = 2;
- }
- HistoryArray historyArray;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement