- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个程序,代码如下,它监视一个文本文件并逐行获取数据并将输出打印到另一个文件。
当程序运行时,并非所有数据都会出现在文件中。文本文件将在几天内写入。
我需要能够模拟程序写入文本输入文件。我该怎么做?
我在 Windows 7 上运行,为了测试这一点,我运行了以下命令行:
类型 CON>input.txt
但是当我运行代码时, is null ,因此代码立即返回。我怎样才能解决这个问题,以便代码正确打开文件。我还需要它继续“轮询”(不确定这是否是正确的术语),直到它看到“e”字符作为该行的第一个字符,然后才能关闭。
我使用参数运行程序:myprog.exe input.txt output.txt
这是代码:
/* Prints ranges of numbers in format n number1 number2 where character n
indicates 2 numbers to follow. print from n1+1 to n2. e indicates end
of numbers to process.
*/
#include <stdio.h>
int main(int argc, char* argv[]) {
char s[100];
int mn, mx;
int items = 0;
if(argc == 3) {
FILE* in=fopen(argv[1],"r+");
FILE* out=fopen(argv[2],"w");
if(in && out) {
setbuf(in, NULL);
setbuf(out, NULL);
while((items = (fscanf(in, "%s %d %d", &s, &mn, &mx))) > 0) {
switch(s[0]) {
case 'n':
/* print nos. to out */
while(mn++ < mx) {
fprintf(out, "%d\n", mn);
fflush(out);
}
break;
case 'e': fclose(in); fclose(out); return 0;
default:
/* error */
break;
}
}
fclose(in);
fclose(out);
}
} else {
fprintf(stderr, "Wrong no arguments\n");
}
return 0;
}
最佳答案
我所要做的就是删除打开输入文件时的+:
FILE* in=fopen(argv[1],"r");
我猜测,如果我将标准输入重定向到输入文件,那么标准输入只是一种方式 - 因此不允许输入文件可写。
关于c - 如何编写监视文本文件中新数据的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22122096/
我需要记录在网页上执行的事件。 例如。填写登记表。 记录器应捕获关键字条目和在页面上执行的点击,并在请求时回放。同时记录器还应该捕获生成事件的实际元素。说当我在 firstName 中键入 记录器应
我是一个 Jest 新手,我正在为我的 React 应用程序编写单元测试,该应用程序使用 redux 并使用 Typescript 编写。 我的容器组件包含这段代码: const mapDispatc
我想将一些批处理类型的作业从 cron 转移到 Monit,但正在努力让它们正常工作。这些脚本通常每天运行一次,但有时必须在当天晚些时候重新运行。目标是利用 monit 和 m/monit 前端重新运
我正在尝试测试一个组件调用 detectChanges上面注入(inject)了ChangeDetectorRef 我已经逐步完成了代码,它肯定被调用了,但似乎我在组件和测试中得到了不同的 Chang
我想知道是否有一种很好的方法来监视 SharePoint 上的文档库的更改(添加新文件、更改/ checkin 文件、删除文件等) 基本上,什么System.IO.FileSystemWatcher在
是否可以监视 R 正在使用或已用于调用函数的内存量?例如,我有一个任意函数,例如: smallest.sv <- function(){ A <- matrix(rnorm(1e6), 1e3);
这是一个简单的问题,但令人费解...... Azure 服务中是否有统计数据来监控数据工厂被访问的次数? 那么,举个例子,如果一个自动化系统被设置为通过恶意意图耗尽对 ADF 进行持续的 API 调用
Kafka提供了监控当前偏移量和最新偏移量的能力。同样,azure eventhub是否公开任何api来持续监视分区的当前偏移量和最新可用偏移量? 最佳答案 扩展上述答案,您可以看到两种方式的偏移。
是否有系统 View 或 DMV 记录我的数据仓库恢复和暂停的时间以及执行恢复和暂停的帐户?我环顾四周,似乎找不到具有开/关时间戳的 View 。或者甚至是显示放大和缩小的历史时间戳的 View 。
我一直在研究Microsoft Azure 事件中心。我的目标是找到一种提供自动可扩展性的方法。这是一项实验性工作,我实际上只是想知道我可以使用 Azure 事件中心做什么。我无法访问 Azure 平
我有一个在 azure 中运行的辅助角色。 我正在使用标准跟踪诊断,我可以使用 Visual Studio 中的服务器资源管理器查看该诊断。 但是,它很难涉水,速度很慢等等。 谁能推荐一个插件、工具、
我们将 Azure Function 与 Node.js 结合使用。 在Azure门户UI中,在每个函数调用日志列表旁边(在“监视器”选项卡中),我们看到两个计数器:“最近成功计数”和“最近错误计数”
是否有系统 View 或 DMV 记录我的数据仓库恢复和暂停的时间以及执行恢复和暂停的帐户?我环顾四周,似乎找不到具有开/关时间戳的 View 。或者甚至是显示放大和缩小的历史时间戳的 View 。
我一直在研究Microsoft Azure 事件中心。我的目标是找到一种提供自动可扩展性的方法。这是一项实验性工作,我实际上只是想知道我可以使用 Azure 事件中心做什么。我无法访问 Azure 平
我有一个在 azure 中运行的辅助角色。 我正在使用标准跟踪诊断,我可以使用 Visual Studio 中的服务器资源管理器查看该诊断。 但是,它很难涉水,速度很慢等等。 谁能推荐一个插件、工具、
是否可以获取 channel 消息的副本? (而不是从 channel 接收和删除消息) 这个想法是记录一个 channel 的消息。 最佳答案 Is it possible to get copy
我正在尝试使用 Mockito监视路径 em> dirSpy = spy(Files.createTempDirectory(DIR_NAME)); 我收到一条错误消息 Mockito cannot
我的组件具有以下功能: updateTransactions() { let notes = this.createNotes() let delTransactions = th
我想测试一些在 React 组件的 componentDidMount 生命周期方法中调用的自定义方法。 componentDidMount() { getData().then(res
我的 $scope 中有一个对象,其中包含一些属性,例如: $scope.content = { name : 'myname', description : 'mydescrip
我是一名优秀的程序员,十分优秀!