mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 05:21:49 +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;
|
i = 0;
|
||||||
counter++;
|
counter++;
|
||||||
char words[counter][80];
|
char **words = (char **)malloc(counter * sizeof(char *));
|
||||||
|
|
||||||
/* initalizes words-array with empty strings */
|
/* initalizes words-array with empty strings */
|
||||||
for (i = 0; i < counter; i++)
|
for (i = 0; i < counter; i++)
|
||||||
{
|
{
|
||||||
|
words[i] = (char *)malloc(80 * sizeof(char));
|
||||||
strcpy(words[i], "");
|
strcpy(words[i], "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,5 +84,9 @@ char *abbreviate(const char *phrase)
|
|||||||
strcat(acr, words[i]);
|
strcat(acr, words[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < counter; i++)
|
||||||
|
free(words[i]);
|
||||||
|
free(words);
|
||||||
|
|
||||||
return acr;
|
return acr;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user