write characters to file

#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 close
 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324971538&siteId=291194637