f扫描文本文件时如何跳过一行? [英] How to skip a line when fscanning a text file?

查看:98
本文介绍了f扫描文本文件时如何跳过一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在阅读之前扫描文件并跳过一行文本.我试过了:

I want to scan a file and skip a line of text before reading. I tried:

fscanf(pointer,"\n",&(*struct).test[i][j]);

但是这种语法只是从第一行开始.

But this syntax simply starts from the first line.

推荐答案

fgets将获得一行,并从下一行开始设置文件指针.然后,您可以在第一行之后开始阅读所需内容.

fgets will get one line, and set the file pointer starting at the next line. Then, you can start reading what you wish after that first line.

char buffer[100];
fgets(buffer, 100, pointer);

只要您的第一行少于100个字符,它就可以工作.否则,您必须检查并循环.

It works as long as your first line is less than 100 characters long. Otherwise, you must check and loop.

这篇关于f扫描文本文件时如何跳过一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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