C 语言实例 - 将字符串写入文件

C 语言教程 · 2019-02-21 11:11:24

将字符串写入文件。

实例

#include <stdio.h> #include <stdlib.h> /* exit() 函数 */ int main() { char sentence[1000]; FILE *fptr; fptr = fopen("codercto.txt", "w"); if(fptr == NULL) { printf("Error!"); exit(1); } printf("输入字符串:\n"); fgets(sentence, (sizeof sentence / sizeof sentence[0]), stdin); fprintf(fptr,"%s", sentence); fclose(fptr); return 0; }

输出结果为:

输入字符串:
codercto.com

打开文件 codercto.txt:

$ cat codercto.txt 
codercto.com

点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html

查看所有标签

ActionScript 3.0 Cookbook

ActionScript 3.0 Cookbook

Joey Lott、Darron Schall、Keith Peters / Adobe Dev Library / 2006-10-11 / GBP 28.50

Well before Ajax and Microsoft's Windows Presentation Foundation hit the scene, Macromedia offered the first method for building web pages with the responsiveness and functionality of desktop programs......一起来看看 《ActionScript 3.0 Cookbook》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具