Thanks for your help Elysia. I've made your specified changes. That, along with the fact that the line right before the return in storeLine should have been
Code:
pwalker -= (length-1)
...seems to have been the problem. Also, prefix subtraction should have been used in the end printing.
Here's the final code for any other people who may need it in the future (i've made changes to storeLine to make it more efficient):
Code:
char* storeline5_13(char** pointcnt, char* line, int length)
{
*pointcnt = (char *) malloc(sizeof(char) * length);
while(*line != '\n')
*((*pointcnt)++) = *line++;
**pointcnt = '\0';
*pointcnt -= (length - 1);
return *pointcnt;
}
void tail5_13(int n)
{
int maxpoint = 3;
size_t maxlength = sizeof(char) * 10;
char **pointptr = malloc(sizeof(char *) * maxpoint);
char **pointcnt = pointptr;
char *lineptr = malloc(sizeof(char) * maxlength);
int numlines = 0;
int printnum = 0;
int c;
while((c = getline(&lineptr, &maxlength, stdin)) > 1)
{
if(numlines < maxpoint)
{
*pointcnt = storeline5_13(pointcnt, lineptr, c);
pointcnt++;
}
else
{
maxpoint *= 2;
printf("Increased pointer amount to %d\n", maxpoint);
pointptr = (char **) realloc(pointptr, sizeof(char *) * maxpoint);
pointcnt = pointptr + numlines;
*pointcnt = storeline5_13(pointcnt, lineptr, c);
pointcnt++;
}
numlines++;
}
if(n <= numlines)
printnum = n;
else
printnum = numlines;
while(printnum-- > 0 )
printf("%s\n", *(--pointcnt));
}