读取一个特定字符的文本文件 [英] Reading a text file up to a certain character

查看:64
本文介绍了读取一个特定字符的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的难题.我有一个文件,希望读取所有字符,直到程序击中#"为止,并忽略#"之后该行上的所有内容.例如

Here's my dilemma. I have a file, and wish to read in all characters up until the program hits a '#', and ignore everything on that line after the '#'. For example

0 4001232 0#注释,丢弃

0 4001232 0 #comment, discard

这令人沮丧,因为感觉有一个非常简单的解决方案.谢谢!

This is frustrating, as it feels like there is a very simple solution. Thanks!

推荐答案

FILE *f = fopen("file.txt", "r");
int c;
while ((c = getc(f)) != '#' && c != EOF)
   putchar(c);

这篇关于读取一个特定字符的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆