#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!=' ') ; fclose(fp);//关掉close }