C 语言创建文件,写入内容 fputc

#include "stdafx.h"

#include <stdlib.h>/*为了调用system("PAUSE");*/
#include <time.h>/*为了调用time;*/
#include <stdio.h>
#include <string>
#include <windows.h>

int main(int argc , char* argv[])
{
  FILE *fp;
  char  ch, filename[100];
  
  printf("Input the file name:");/*输入文件名字*/
  scanf ("%s", filename);


  if((fp=fopen(filename,"w"))==NULL) /*创建文件*/
  {
        printf("Open file fail!\n");
return C_SYS_ERR;
  }


  printf("Input ch:");
  ch =getchar();  /*输入文件内容*/ 
  while(ch!='#')
  {
        fputc(ch,fp);
ch =getchar();
  }
 
  fclose(fp);
  
 


  system("PAUSE");
  return C_SYS_OK;
}

猜你喜欢

转载自blog.csdn.net/shayne_lee/article/details/80376876
今日推荐