/*
名称:C语言输入输出
说明:fputc(ch,fp):把字符ch写到fp制定的文件中。
fgetc(fp):返回一个从fp指向的文件中一个字符。
fgets(str,n,fp):从fp指向的文件中读取n-1个字符放到str中。
fputs(str,fp):将str中的字符串输出到fp指向的文件中
fread(p,size,n,fp):从fp指向的文件中,读取n个数据项,存放到p指向的储存区域。
fwrite(p,size,n,fp):将p指向的区域中的n个数据项写入fp指向的文件中。
*/
#include<stdio.h>
typedef struct stu
{
int num; //学号
char name[10]; //姓名
}Stu;
int Main()
{
FILE *in,*out;
int i;
char c;
char str[10];
Stu st[2] = {10,"xiaopan",20,"xiaoming"};
Stu st1[2];
out = fopen("test.txt","w");
if(out == NULL)
printf("cann't open the file");
else
{
//写出测试
//fputs("this is a test!\n",out); //写入一个字符串
//fputc('a',out); //写入字符一个字符
//fwrite(st,sizeof(Stu),2,out); //写入一块数据
//fprintf(out,"%d--%s",30,"xiaoyun"); //格式化输出
}
fclose(out);
in = fopen("test.txt","r");
if(out == NULL)
printf("cann't open the file");
else
{
//读入测试
//c = fgetc(in); //读入一个字符
//fgets(str,10,in); //读入一个字符串
//fread(st1,sizeof(Stu),2,in); //读入一块数据
//fscanf(in,"%d--%s",&i,str); //格式化输入
printf("%d--%s",i,str);
}
fclose(in);
return 0;
}