1.13标准C库对文件操作引入
#include<stdio.h>
#include<string.h>
int main()
{
//FILE *fopen(const char *path, const char *mode);//写入的路径;写入的模式
FILE *fp;
char *str = "chenlichen hen shuai";
char readBuf[128] = {0};
fp = fopen("./chen.txt","w+");//*mode是指针,所以要用双引号“”
// size_t fwrite(const void *ptr, size_t size, size_t nmemb,FILE *stream);
// 写入的是什么,写入的长度是多好,写入多少次,写进去哪里
// ptr buf
// size sizeof char
//geshu
//which file
fwrite(str,sizeof(char),strlen(str),fp);
// fwrite(str,sizeof(char)*strlen(str),1,fp);
// 上面的这两种写法都可以
// int fseek(FILE *stream, long offset, int whence);
fseek(fp,0,SEEK_SET);
// size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
fread(readBuf,sizeof(char),strlen(str),fp);
printf("read data: %s\n",readBuf);
return 0;
}