如何在fscanning .txt文件时跳过第一行? [英] How to skip the first line when fscanning a .txt file?

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

问题描述

我使用C,我的知识是非常基本的。
我想扫描一个文件,并获得第一或第二行后的内容... ...
$ b $我试过:

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

但是这个语法只是从第一行开始= \



这怎么可能?



谢谢。

解决方案

fgets将获得一行,并设置从下一行开始的文件指针。然后,你可以在第一行之后开始阅读你想要的东西。

  char buffer [100]; 
fgets(buffer,100,po​​inter);

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


I am using C and my knowledge is very basic. I want to scan a file and get the contents after the first or second line only ...

I tried :

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

But this syntax simply starts from the first line =\

How is this possible ?

Thanks.

解决方案

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);

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

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

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