C语言输入输出函数总结

/*
名称: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;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值