c - 从文件中的特定位置读取特定数据(C)
问题描述
如果我有这个包含 Integers 的 .txt 文件:
- //firstRow 14 5
- //secondRow 5
- //fourthRow 3
- //fourthRow 3
如何从第一行读取第二个 整数?谢谢
解决方案
fscanf(fptr, "[^\n]", file);
scanf 函数在第一次遇到时很难理解。您的格式字符串(第二个参数)是错误的。你想要更多类似的东西
int a, b, n;
while( (n = fscanf(fptr, "%d%d", &a, &b)) != EOF ) {
if( n == 2 ) { ... your code here ... }
}
准备好花时间阅读手册。 man fscanf是您的朋友,但需要一些时间来热身。
推荐阅读
- download - wget how to download only newer version of a file
- java - 未找到物业!相同的命名约定
- php - 卷曲错误:无法加载 PEM 客户端证书
- service - 所有 sysv 服务都返回退出代码 1(服务
开始/状态/停止) - javascript - weird seconds offset in js date object in chrome
- c# - Trigger TagHelper from another TagHelper
- c# - 如何实现 Ellipse WPF 扩展?
- php - How to get an access to webpage from external php file
- apache-kafka - kafka use-case for error topics
- sql - Oracle 11g:表校验和或哈希