|
|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
#include <ctype.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
void trimLeft(char *input) { |
|
|
|
size_t length = strlen(input); |
|
|
@ -22,3 +23,27 @@ void trimRight(char *input) { |
|
|
|
index--; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
char *readInput() { |
|
|
|
size_t bufferSize = 100; |
|
|
|
char *buffer = malloc(bufferSize*sizeof(char)); |
|
|
|
char c; |
|
|
|
int index = 0; |
|
|
|
do { |
|
|
|
c = fgetc(stdin); |
|
|
|
if (!(bufferSize > index)) { |
|
|
|
char *newBuffer = malloc(2*bufferSize*sizeof(char)); |
|
|
|
for (int i = 0; i < bufferSize; i++) { |
|
|
|
newBuffer[i] = buffer[i]; |
|
|
|
} |
|
|
|
bufferSize *= 2; |
|
|
|
} |
|
|
|
buffer[index] = c; |
|
|
|
index++; |
|
|
|
} |
|
|
|
while(c != '\n' && c != EOF); |
|
|
|
buffer[index - 1] = '\0'; |
|
|
|
trimLeft(buffer); |
|
|
|
trimRight(buffer); |
|
|
|
return buffer; |
|
|
|
} |