C语言教程 fprintf()函数的作用

2024-10-14 02:47:08

1、新建一个fprintf()函数的作用 项目,如图所示:

C语言教程 fprintf()函数的作用

2、添加一个 test.c 文件,如图所示:

C语言教程 fprintf()函数的作用

3、包含需要用到的两个头文件,如图所示:

C语言教程 fprintf()函数的作用

4、输入 main() 主函数,并且添加参数和返回值,如图所示:

C语言教程 fprintf()函数的作用

5、使用 fopen() 函数打开 file.txt 文件,代码如图所示:

C语言教程 fprintf()函数的作用

6、使用 fprintf() 函数往文件file.txt 写入文本,如图所示:

C语言教程 fprintf()函数的作用

7、运行程序,接着打开 file.txt 文件,查看文本是否写入成功,如图所示:

C语言教程 fprintf()函数的作用

8、至此,本教程结束!

猜你喜欢