Skip to content

Instantly share code, notes, and snippets.

@johnhmj
Created October 19, 2010 07:57
Show Gist options
  • Save johnhmj/633811 to your computer and use it in GitHub Desktop.
Save johnhmj/633811 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFFERSIZE 1024
//
void MyFile(const char* fn);
int main(void)
{
MyFile("C:\\123.txt");
//
system("PAUSE");
return 0;
}
void MyFile(const char* fn)
{
FILE * pFile_Read = NULL;
char buffer[BUFFERSIZE] = {0};
// 開檔:讀取檔案
pFile_Read = fopen(fn, "r");
if ( pFile_Read == NULL )
{
printf("檔案開啟失敗...\n");
}
else
{
printf("%s ", fn);
while( feof(pFile_Read) == 0 ){
fgets(buffer, BUFFERSIZE, pFile_Read);
printf("%s ", buffer);
}
fclose(pFile_Read);
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment