mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-25 06:49:36 +03:00
use dynamic memory
This commit is contained in:
parent
5360573994
commit
055d782275
@ -38,11 +38,12 @@ char *abbreviate(const char *phrase)
|
||||
|
||||
i = 0;
|
||||
counter++;
|
||||
char words[counter][80];
|
||||
char **words = (char **)malloc(counter * sizeof(char *));
|
||||
|
||||
/* initalizes words-array with empty strings */
|
||||
for (i = 0; i < counter; i++)
|
||||
{
|
||||
words[i] = (char *)malloc(80 * sizeof(char));
|
||||
strcpy(words[i], "");
|
||||
}
|
||||
|
||||
@ -83,5 +84,9 @@ char *abbreviate(const char *phrase)
|
||||
strcat(acr, words[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < counter; i++)
|
||||
free(words[i]);
|
||||
free(words);
|
||||
|
||||
return acr;
|
||||
}
|
Loading…
Reference in New Issue
Block a user