标准C库打开创建文件

#include <stdio.h>
#include <string.h>
int main()
{
//FILE *fopen(const char *pathname, const char *mode);
//size_t fwrite(const void *ptr, size_t size, size_t nmemb,FILE *stream);
//size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
FILE *fp;
char readBuf[128]={0};
char *str = “cao kuangyuan hen shuai!”;
fp = fopen("./cao.txt",“w+”);
fwrite(str,sizeof(char),strlen(str),fp);
fseek(fp,0,SEEK_SET);
//fwrite(str,sizeof(char)*strlen(str),1,fp);
fread(readBuf,sizeof(char),strlen(str),fp);
printf(“read data: %s\n”,readBuf);
return 0;;
}

©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页