多语言版本网站制作,2016网站谷歌权重,wordpress去除cat,主机域名网站源码文章目录 1 函数原型2 参数3 返回值4 示例4.1 示例14.2 示例24.3 示例3 1 函数原型
fputc()#xff1a;将一个字符发送至指定流stream#xff0c;函数原型如下#xff1a;
int fputc(int c, FILE *stream);2 参数
fputc()函数有两个参数c和stream#xff1a;
参数c是待… 文章目录 1 函数原型2 参数3 返回值4 示例4.1 示例14.2 示例24.3 示例3 1 函数原型
fputc()将一个字符发送至指定流stream函数原型如下
int fputc(int c, FILE *stream);2 参数
fputc()函数有两个参数c和stream
参数c是待输出字符的ASCII码值或字符常量类型为int型参数stream是一个指向FILE类型结构的指针stream指定了fputc()函数要写入的流可以是文件流也可以是标准输出流当是文件流时stream等于fopen()函数的返回值当是标准输入流时stream等于stdout。
3 返回值
fputc()函数的返回值类型为int型
输出成功返回参数c的值输出失败返回EOF。
C语言标准描述如下
1. Each of these functions returns the character written. For fputc and _fputchar, a return value of EOF indicates an error.4 示例
4.1 示例1
以ASCII码值和字符常量的形式输出单个字符代码如下所示
int main()
{FILE* fp;if ((fp fopen(1.txt, w)) NULL){printf(Failed to open file\n);exit(1);}char str1[] { 97, 98, 99, 100, 101, 102 };char str2[] { a, b, c, e, e, f };int i 0;for (i 0; i 6; i){fputc(str1[i], fp);}fputc(\n, fp);for (i 0; i 6; i){fputc(str2[i], fp);}fclose(fp);return 0;
}代码运行结果如下图所示 4.2 示例2
从键盘读取字符串hello world并打印代码如下所示
int main()
{while ((fputc(getchar(),stdout)) ! \n);return 0;
}代码运行结果如下图所示 4.3 示例3
从字符数组读取字符串hello world并写文件代码如下所示
int main()
{FILE* fp;if ((fp fopen(2.txt, w)) NULL){printf(Failed to open file\n);exit(1);}char str[] hello world;int i 0;while (1){if (str[i] \0){break;}else{fputc(str[i], fp); }i;}fclose(fp);return 0;
}代码运行结果如下图所示