C 练习实例97

C 语言教程 · 2019-02-22 18:13:27

题目:从键盘输入一些字符,逐个把它们送到磁盘上去,直到输入一个#为止。

程序分析:无。

实例

// Created by www.codercto.com on 15/11/9. // Copyright © 2015年 码农教程. All rights reserved. // #include<stdio.h> #include<stdlib.h> int main() { FILE*fp=NULL; char filename[25]; char ch; printf("输入你要保存到的文件的名称:\n"); gets(filename); if((fp=fopen(filename,"w"))==NULL) { printf("error: cannot open file!\n"); exit(0); } printf("现在你可以输入你要保存的一些字符,以#结束:\n"); getchar(); while((ch=getchar())!='#'){ fputc(ch,fp); } fclose(fp); system("pause"); return 0; }

以上实例运行输出结果为:

输入你要保存到的文件的名称:
test.txt
现在你可以输入你要保存的一些字符,以#结束:
www.codercto.com
#

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

查看所有标签

Haskell Programming from first principles

Haskell Programming from first principles

Christopher Allen、Julie Moronuki / 2015 / USD 59.00

I am writing this book because I had a hard time learning Haskell. It doesn't have to be that way. I've spent the last couple years actively teaching Haskell online and in person. Along the way, I ......一起来看看 《Haskell Programming from first principles》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

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

在线 XML 格式化压缩工具

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

html转js在线工具