Then use this code:
/* using the getline
located here
<
http://www.cpax.org.uk/prg/portable/c/libs/sosman/index.php>
*/
#include <stdio.h>
#include <stdlib.h>
#include "getline.h>
int main(int argc, char **argv) {
char *p, *q = NULL;
FILE *fp;
if(argc != 2) return EXIT_FAILURE;
if((fp = fopen(argv[1], "r")) == NULL) return EXIT_FAILURE;
while((p = getline(fp)) != NULL) {
free(q);
q = p;
}
if(!feof(fp)) {
free(q);
fclose(fp);
return EXIT_FAILURE;
}
/* q is now the last line */
printf("Last line: %s\n", q);
free(q);
fclose(fp);
return 0;
}
Why don't you just point out and correct vipstar's error?
I'll do it for him:
I meant 'char *p, *lastline = NULL;' where 'char *p, lastline = NULL;'
is.
I'm not a troll.