Skip to content

Commit

Permalink
Replace inSize with 'i' and use a standard for loop to handle increme…
Browse files Browse the repository at this point in the history
…nting.

	modified:   src/nms.c
  • Loading branch information
bartobri committed Sep 20, 2017
1 parent 40da205 commit 65ded7d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/nms.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define INPUT_GROWTH_FACTOR 2

int main(int argc, char *argv[]) {
int c, o, inSize = 0, inCapacity = INITIAL_CAPACITY;
int c, o, i, inCapacity = INITIAL_CAPACITY;
char *input = NULL;

// Processing command arguments
Expand Down Expand Up @@ -46,24 +46,24 @@ int main(int argc, char *argv[]) {
}
}

// Allocate memory for our input buffer
if ((input = malloc(inCapacity + 1)) == NULL) {
fprintf (stderr, "Memory Allocation Error! Quitting...\n");
return 1;
}

// Geting input
while ((c = getchar()) != EOF) {
++inSize;
if (inSize > inCapacity) {
for (i = 0; (c = getchar()) != EOF; ++i) {
if (i >= inCapacity) {
inCapacity *= INPUT_GROWTH_FACTOR;
input = realloc(input, inCapacity + 1);
if (input == NULL) {
fprintf (stderr, "Memory Allocation Error! Quitting...\n");
return 1;
}
}
input[inSize - 1] = c;
input[inSize] = '\0';
input[i] = c;
input[i+1] = '\0';
}

// Execute effect
Expand Down

0 comments on commit 65ded7d

Please sign in to comment.