N
Nick Keighley
please include the subject in the body of your email:
"sorting the input"
take a look at realloc(). Initally malloc() a block of pointers
and when it fills up call realloc().
or fputs()
sounds fine to me. Which bit are you stuck on?
"sorting the input"
1st I think of creating an array of pointers of size 100 as this is the
maximum input I intend to take. I can create a fixed size array but in the
end I want my array to expand at run-time to fit the size of input. I am
not able to come up with anyting all all and doing:
take a look at realloc(). Initally malloc() a block of pointers
and when it fills up call realloc().
char* arr_of_pointers[100];
seems like a completely wrong idea as this is a static array. I want to
take the input and then decide how much memory I need and then malloc the
array of that size. I came up with K&R2 idea:
1.) read and save the input lines till the user hits the EOF
2.) sort them
3.) print them
I am pretty much confused on what to start with. Can I have your ideas in
solving this problem ? All I can think of is:
use sort algorithm from the standard library to sort the lines.
print the lines using %s as argument in printf().
or fputs()
sounds fine to me. Which bit are you stuck on?