当行中出现错误时,如何将文件指针移动到下一行 [英] How to move the file pointer to the next line when there is an error in line

查看:333
本文介绍了当行中出现错误时,如何将文件指针移动到下一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应该读取文本文件的应用程序,该文件包含使用C文件处理函数的.jpg文件的路径。

要求是逐行读取文件但是如果线路的路径是错误的,它不应该再读取当前线路并且应该移动到下一条线路。



任何人都可以帮助我如何移动文件指针指向当前行中的下一行。谢谢

I am working on an application that should read a text file which contains the path of the .jpg files using C file handling functions.
The requirement is to read the file line by line but if the path of the line is wrong, it should not read the current line any more and should move into the next line.

Can any one plz help me how to move the file pointer to the next line while it is in the current line. Thank you

推荐答案

http://www.cplusplus。 com / reference / cstdio / fgets / [ ^ ]

如果丢弃内容,请将第二个字符设置为0.



有一个函数可以将函数指针设置为a具体位置: fseek()。但是,您需要知道当前位置的精确位置或偏移量(以字节为单位)才能使用此功能。如果你没有,那么唯一的方法是继续阅读并丢弃结果。
http://www.cplusplus.com/reference/cstdio/fgets/[^]
Set the second character to 0 if you discard the contents anyway.

There's one function to set the function pointer to a specific position: fseek(). However, you need to know the exact position or offset from the current position (in bytes) to use this function. If you don't have that, then the only way is to keep on reading and discard the results.


这篇关于当行中出现错误时,如何将文件指针移动到下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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