Answer the question
In order to leave comments, you need to log in
Dynamic array of strings in pure C
Given the moment that I have little time and there is practically no search for this issue, I immediately want to ask the powers that be.
Please provide a working example of a dynamic array of strings where input data is read from a file.
That is, there is a certain file where we put IP addresses in a column, you need to read these IP addresses and put them in a dynamic array that can be used as a moto. Thank you.
Answer the question
In order to leave comments, you need to log in
pastebin.com/eFRk5LN2
Dynamically allocated array of strings in pure C. The truth is, you don't need to do that. It is necessary to allocate a small static buffer (array) for the string (no more than 15 characters - the maximum size of the ip address). Read all lines into this buffer one by one. Convert them to a numeric representation of ip and write them to a pre-created/sallocated static array.
Keywords: malloc, realloc.
Here is a direct example, not very high quality, but still:
www.c.happycodings.com/Data_Structures/code10.html Realloc
is done here every time we read a new line from stdin, but it would be nice to allocate memory in slightly larger chunks in advance, and re-allocate , respectively, not every time, but when the place in the array is over.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question