file.c

来自「压缩包里面的都是精致的基本C语言小程序」· C语言 代码 · 共 63 行

C
63
字号
#include "error.h"#include "mystdlib.h"#include "file.h"file fileOpen (char *fname, char *mode){  file fp = fopen (fname, mode);    if (!fp)    exception ("bad file pointer: file.c\n");  return fp;}int fileClose (file fp){  return fclose (fp);}int fileGetChar (file fp){  return getc (fp);}int filePutChar (int c, file fp){  putc (c, fp);  return c;}str fileGets (file fp){  int maxSize = 1024;  char *temp = checkedMalloc (maxSize * sizeof (char));    if (NULL == fgets (temp, maxSize, fp))  {    //error ("no content in file: file.c\n");    checkedFree (temp);    return NULL;  }  if (!(strValid (temp, maxSize)))    exception ("space too small: file.c\n");  str sss = newStr (temp);  checkedFree (temp);  return sss;}int filePuts (str line, file fp){  char *s = strToCharStar (line);    int i = fputs (s, fp);      if (EOF == i)    error ("file write error: file.c\n");  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?