- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我一直在为我的 CIS 类(class)做一个小练习,我对 C 用来读取文件的方法感到非常困惑。我真正需要做的就是逐行读取文件并使用从每一行收集的信息进行一些操作。我尝试使用 getline 方法和其他方法,但没有成功。我的代码目前如下:
int main(char *argc, char* argv[]){
const char *filename = argv[0];
FILE *file = fopen(filename, "r");
char *line = NULL;
while(!feof(file)){
sscanf(line, filename, "%s");
printf("%s\n", line);
}
return 1;
}
现在我遇到了 sscanf 方法的段错误,我不确定为什么。我是一个彻头彻尾的 C 菜鸟,只是想知道我是否遗漏了一些大局。谢谢
最佳答案
如此少的行中有如此多的问题。我可能忘记了一些:
所以
#include <stdio.h>
int main(int argc, char* argv[])
{
char const* const fileName = argv[1]; /* should check that argc > 1 */
FILE* file = fopen(fileName, "r"); /* should check the result */
char line[256];
while (fgets(line, sizeof(line), file)) {
/* note that fgets don't strip the terminating \n, checking its
presence would allow to handle lines longer that sizeof(line) */
printf("%s", line);
}
/* may check feof here to make a difference between eof and io failure -- network
timeout for instance */
fclose(file);
return 0;
}
关于c - 在 C 中逐行浏览文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9206091/
我遇到一个问题,即我的抓取工具正在跳过没有浏览引荐来源网址的浏览页面。我正在尝试解析 URL 中包含/browse/的所有页面,无论引用者如何。 以下是我的代码(根据 paul t 更新): from
我有4个屏幕。 X,A,B,C。导航模式应如下所示 这是代码 X 屏幕 class X extends StatelessWidget { @override Widget build(Bui
我想用 java 编写一个简单的网络浏览器,这是我的代码! import javax.swing.*; import java.io.*; import java.awt.*; import java
这个问题在这里已经有了答案: A home button in iOS 5, xcode 4.2, Story board (2 个回答) 8年前关闭。 来自 FirstView到SecondView
我使用 C#/ASP.Net 在 IIS7 中创建虚拟目录,以便外部人员可以浏览各种文档。 一切看起来都不错,除了浏览是一种沉闷的文本格式。当他们浏览到文件夹时,我如何创建更多的“Windows 资源
我想我在 Chrome 或 Internet Explorer 中见过 Gmail 这样做,但我从未在 Firefox 中见过它。我想我还是会问一下。是否可以在不需要的情况下进行文件上传?我看到你可以
我是 Java 的新手,作为第一次阅读,我阅读了几本有关 Java 语言的书籍。 我有几个关于 Java 文档的问题。如何“导航”它们?是否可以仅使用 Javadoc 来学习新概念? 这是一个示例 -
我有一个解析网络,现在我想浏览标签,或显示图表。我怎样才能得到图表?或者在树中导航。显示第一步然后其他等。并了解这棵树是如何 build 的。 import urllib from lxml impo
考虑以下情况: 杀戮戒指中的 N 项。需要拉取的项目是项目#k 数值论证解决方案不会真正起作用,因为计算或跟踪杀死环中事物的位置很烦人。 最佳答案 实际问题是什么?按 C-y 然后按 M-y k 次有
这是我之前的 question 的后续。 我试图从 here 了解 Haskell 中的列表拆分示例: foldr (\a ~(x,y) -> (a:y,x)) ([],[]) 我可以阅读 Haske
是否有任何 vim 工具通过 Latex 文档结构提供有效的导航。拥有像 NERDTree 面板这样的东西来表示 latex 文档的部分/子部分结构会非常有用。 最佳答案 扩展 mnosefishs
您好,我的应用程序中有一个模态视图 Controller ,当按下某个按钮时,该 Controller 会消失,并且其中带有 UITableView 的 View 会使用导航 Controller 滑
Glances v2.11.1 with psutil v5.4.3 /usr/lib/python3.6/site-packages/psutil/_pslinux.py:1152: Runtime
我正在使用 Eclipse,我希望我可以通过按 STRG 在以驼峰式书写的单词之间跳转。现在我正在使用 Sublime,我找不到这样做的快捷方式,也找不到实现它的插件。 下面的例子说明了我的问题 aF
我的主程序提示用户浏览文件以便使用 ffmpeg 进行转换。这是文件浏览的格式: 1. Select audio file for conversion ( mp3, wma):
我正在尝试浏览 SVN 存储库,而不必检查它: 是否可以在本地(Unix 上)执行此操作? 这可以通过 ssh 访问实现吗? 最佳答案 svn ls 有效。例如 svn ls http://my.sv
我有一个网站,其中列出了数据库中的企业列表。在每个页面上,您可以执行不同的操作,例如将其转发给 friend 、打印页面等。我的问题是我可以使用谷歌分析来跟踪每个列表的展示次数和浏览次数吗?因此,如果
在 Dart 我有一个嵌套的元素列表 void main() { var diction = {'1':'Alpha','2':'Beta','3':{'x':'Football','y':'
当我们的用户单击网页上的浏览按钮来上传任何文件时,我想更改窗口位置。我会给你一个场景 - 我的 html 表单上有一个浏览按钮,当用户单击一个弹出窗口时,该位置默认为“我的文档”。 实际上我想在单击“
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve th
我是一名优秀的程序员,十分优秀!