博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

小猪娃


One World One Dream
xuanfei.cublog.cn


c putc&getc 函数学习

/*



putc(将一指定字符写入文件中)
相关函数
fopen,fwrite,fscanf,fputc
表头文件
#include<stdio.h>
定义函数
int putc(int c,FILE * stream);
函数说明
putc()会将参数c转为unsigned char后写入参数stream指定的文件中。虽然putc()与fputc()作用相同,但putc()为宏定义,非真正的函数调用。
返回值
putc()会返回写入成功的字符,即参数c。若返回EOF则代表写入失败。
范例:

*/

#include<stdio.h>
int main(int argc, char **argv)
{
    FILE *fp;
    char c;
    printf("Please input \n\n");
    fp = fopen("INPUT", "w");

/*Get a character from keyboard*/
    while ((c = getchar()) != EOF)

/*Write a character to INPUT*/
        putc(c, fp);
/*Close the file INPUT*/
    fclose(fp);
    printf("\nData Output\n\n");

/*Reopen the file INPUT*/
    fp = fopen("INPUT", "r");

/*Read a character from INPUT*/
    while ((c = getc(fp)) != EOF)
        printf("%c", c);
/*Close the file INPUT*/
    fclose(fp);

    return 0;


}

 原文地址 http://www
发表于: 2008-02-19 ,修改于: 2008-02-19 20:53,已浏览517次,有评论0条 推荐 投诉


网友评论

发表评论