It's not very efficient, but it should do what you want:
Note that lineCount starts at 0. (The first line is line 0).
char* getLine(FILE *file, int lineNum){
char c;
int lineCount=0, size = 0; // start size at zero, not one
char *line = NULL;
while ((c=getc(file)) != EOF){
if (lineCount==lineNum){
size += 1;
if(line == NULL) {
line = calloc(sizeof(char), size);
} else {
line = realloc(line, size*sizeof(char));
}
char ac[2] = { c, 0 }; // this line is new
strcat(line, ac); // ac is new here
printf("Line: %s\n", line);
if(c == '\n') {
return line;
}
}
if (c=='\n'){
++lineCount;
}
}
printf("Could not find line %d\n", lineNum);
return NULL;
}