Skip to content

Instantly share code, notes, and snippets.

@america
Created December 29, 2013 05:27
Show Gist options
  • Select an option

  • Save america/8167745 to your computer and use it in GitHub Desktop.

Select an option

Save america/8167745 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define BUFSIZE 1024 + 1
int read_file(char *fname)
{
FILE *fp;
char buf[BUFSIZE];
fp = fopen(fname, "r");
if(fp == NULL) {
perror("fopen");
return -1;
}
while(fgets(buf, sizeof(buf), fp) != NULL) {
printf("%s", buf);
}
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment