向文件中写入字符

#include<stdio.h>
  struct student{
    int num;
    char sex;
    float score;
} ;
  union data{
  int k;
  char ch;
  float f;
};
 int main(void){
  FILE *fp;//定义指针
  char ch;
  if((fp=fopen("d:\\yy.txt","w"))==NULL){//fopen方法
      printf("cannot open file,press any key to exit!");
      getchar();
      exit(0);
  }
  do{
    ch=getchar();
    fputc(ch,fp);
  }while(ch!='\n') ;
    fclose(fp);//关掉close
}

猜你喜欢

转载自www.cnblogs.com/sunnybowen/p/8964274.html
今日推荐