c语言基础:char写入一个文件

#include <stdio.h>
#include <string.h>
int write_change_policy(const char* filename,char* buf_policy)
{
    FILE *fp = NULL;
    fp = fopen(filename,"w+");
    if(!fp){
        return -1; 
    }   
    if(fwrite(buf_policy,1,strlen(buf_policy),fp) < 0){ 
        return -1; 
        fclose(fp);
    }   
    fclose(fp);
    return 0;   
}
int main()
{
  char paht[256];
  strcpy(paht,"dsfdfsdfsdf");
  write_change_policy("abc.txt",paht);
   
  system("ls");
  return 0;
}

 

posted on 2021-01-10 00:56  lydstory  阅读(460)  评论(0)    收藏  举报

导航