I know this question has been asked before and I think that I understand that having a segmentation fault means that I have a bad pointer somewhere. Having said that I would really appreciate help trying to figure out where my error is. i have a header file and two source files they are

Header:

```
#ifndef LINEHOLDER_H_INCLUDED
#define LINEHOLDER_H_INCLUDED

#define DEFAULT 100
#define MAXLEN 256
#define MAXLINES 1024
int readlines(char *lineptr[], int maxlines);
unsigned getline2(char *s, int size);
void printlines(char **lineptr, int size, int numlines);

#endif // LINEHOLDER_H_INCLUDED

```

The first Source file is :

```
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "lineholder.h"

int main(int argc, char *argv[])
{
  char *lineptr[MAXLEN];      /* input lines */
  int linecount = 0;
  int tail_count = 0;

   int i;

for (i = 1 ; i < argc ; ++i)
{
    char *arg = argv[i]; 
    if (strcmp(arg, "-n") == 0);
    {
        char *endptr;
        tail_count = strtol(arg, &endptr, 10);     
        if (*endptr == '\0')
            continue;
        fprintf(stderr, "warning , argument `%d' is not an integer\n", 1 + i);
     }
 }
  if (!tail_count)
    tail_count = 10;

  if ((linecount = readlines(lineptr,MAXLINES)) >= 0)
    printlines(lineptr, linecount,tail_count);

  return 0;
}

```

The Second Source file is:

```
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "lineholder.h"

unsigned getline2(char *s, int size);

int readlines(char *lineptr[], int maxlines)
{ 
  int len, nlines;
  char *p, line[MAXLEN];

  nlines = 0;

  while ((len = getline2(line, MAXLEN)) > 0) {
    p = malloc(len);
    if (nlines >= maxlines || p == NULL) {
      return -1;
    } else {
      // line[len-1] = '\n';
      if ((len > 0) && line[len-1] == '\n') line[len-1] = '\n';
      strcpy(p,line);
      lineptr[nlines++] = p;
    }
  }
  return nlines;
}

void printlines(char **lineptr, int size, int numlines)
{
  /* 72 lines, we start on line 62 */
  int print_start;
  int line;

  print_start = size - numlines;
  for (line=print_start; line < size; line++)
    printf("%s", lineptr[line]);
}

unsigned getline2(char *s, int size)
{
  int i, c;

  for (i=0; i<size-1 && (c=getchar()) != EOF && c != '\n'; ++i)
    *s++ = c;
  if (c == '\n') {
    *s++ = c;
    ++i;
  }
  *s = '\0';

  return i;
}

```

After building it out with a makefile I will get an executable called tails
When I run ./tails test.out I receive the segmentation fault core dumped error. Can anyone help me figure out where I am trying to allocate memory where I am not supposed to? 

thanks

I updated the code thanks to the help from you guys but my problem still exists.