- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近安装了 Eclipse CDT Mars 版本来运行 C 程序。我在从文件获取输入时遇到问题。所以,我有一个如下所示的程序:
int main(void) {
//Declarations
int number_of_segments;
int k_constraint;
segment_node *ptr_to_segment_array, *ptr_to_segment_sorted_array;
int no_of_coordinates;
int *ptr_to_solution_array;
int *ptr_to_list_of_segment_identifiers_currently;
int no_of_identifiers_currently=1;
int i,j=1,k=0, l=0;
//setvbuf(stdout, NULL, _IOLBF, 0);
//Input
printf("Enter the number of segments\n");
scanf("%d", &number_of_segments);
printf("Enter the k constraint \n");
scanf("%d", &k_constraint);
no_of_coordinates = number_of_segments*2;
//Dynamically allocate memory to the Array
ptr_to_segment_array = (segment_node*)malloc(sizeof(segment_node)*no_of_coordinates);
ptr_to_segment_sorted_array = (segment_node*)malloc(sizeof(segment_node)*no_of_coordinates);
ptr_to_solution_array = (int*)malloc(sizeof(int)*no_of_coordinates);
ptr_to_list_of_segment_identifiers_currently = (int*)malloc(sizeof(int)*number_of_segments);
/*Now, input the individual segments's coordinates from left to right
** while also assigning the unique numbers to an individual segments' coordinates*/
printf("Enter the coordinates of segments from left to right \n");
for(i=0; i<no_of_coordinates; i++,j++){
scanf(" %d", &(ptr_to_segment_array[i].coordinate));
if(j==1){
ptr_to_segment_array[i].position = 'l';
ptr_to_segment_array[i].identifier = i+1;
}
else if(j==2){
ptr_to_segment_array[i].position = 'r';
ptr_to_segment_array[i].identifier = i+1;
}
if(j==2){
//Reset
j=1;
}
}
return 0;
}
嗯,当然这不是整个程序。这就是它的一瞥。问题是 scanf 语句应该接受输入,而我希望从文件中获取输入。因此,我执行了以下操作:
请注意,编码已设置为 MS932(默认)
现在,我构建它并调试它。我进入输入步骤。然后,我等了几分钟,什么也没发生。就是这样。该程序似乎花费了很长时间,但控制没有移至下一行。
现在,您可能会认为程序本身存在一些错误,是的,可能是这样,但我也在 Ideone.com 上使用自定义输入运行了该程序,并且它确实接受了输入。另外,我使用控制台的输入运行了这个程序,它确实一步一步正确地接受了输入。
那么,为什么它不以这种方式直接从文件中获取输入呢?是记事本/Eclipse 还是其他的编码问题?
感谢任何帮助。
顺便说一句,如果有人想要完整的程序,我很乐意提供。它不是一些专有内容。我纯粹出于教育目的而写作,作为解决某些问题的方法。
最佳答案
我还没有看到你告诉你的程序从文件中读取。所以它只是等待你的输入。
您应该在开头添加此内容:
freopen("input.txt", "r", stdin);
它的作用:它重新打开
的stdin
文件描述符并将input.txt
附加到它。它附加它以供阅读 - 第二个参数是 "r"
但是如果您希望能够从控制台和文件中读取内容,则需要再添加一个:
FILE *in;
in = fopen("input.txt", "r");
您应该将 scanf(...)
替换为 fscanf(in, ...)
fscanf(in, "%d", number);
关于c - Eclipse CDT 火星 : Input from a file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34574596/
我已经用 eclipse-cdt 很好地设置了一个项目。我不是从 eclipse 构建的,但是索引器可以工作,并且我的所有 makefile 设置都被选中,包括第三方库头文件。 然而,我想要的是能够查
我正在使用 Eclipse IDE for C/C++ Developers (Eclipse Ganymede Package - version 3.4.2)在 Windows XP 上使用 Mi
在 eclipse CDT 4.2 中,我只想包含几个文件夹作为资源。例如“/root”是创建项目“myproject”的地方。我只想包含这些文件夹并排除任何其他文件夹。 /根/A /根目录/B /根
我已经下载了最新的 Eclipse CDT 版本 (Helios),并想尝试一些 C++ 编程(很久没有这样做了)。 我试图做“Hello World”项目,但我很快就卡住了。 第一件事 - #inc
我已经离开 Eclipse CDT 一段时间了,并且被 JetBrains 优秀的 IDE 宠坏了(公司不让我拥有 Clion )。诚然,这些主要用于解释型语言,而不是编译型语言,因此评估更简单。 当
有没有办法让 Eclipse CDT 在每次构建项目时自动增加构建版本号?我可以找到 ANT 的解决方案,但我知道这仅适用于 Java 项目。 最佳答案 不,ANT 不仅适用于 Java 项目。它主要
我在 C++ Makefile 项目中使用 Eclipse CDT(Helios 版本,CDT 7.0)。由于我是 Eclipse 的新手,我想知道如何正确管理包含目录。我#include 通常没有任
我有一个包含多个项目的工作区,所有项目都可以正常编译。然而,由于未解析的包含,一些项目在编辑器中给出了很多关于未解析符号的警告。大多数是来自工作区中其他项目或第三方库的头文件。 谷歌搜索表明这是索引器
我想将我的 CDT 项目提交给 SVN。我是关于 CDT 的新手,我想知道描述该项目的文件。 相关文件似乎是: 。项目 .settings(目录) .c项目 .csettings(目录) .proje
有没有办法在eclipse CDT中为类生成模板自定义包含保护的格式?当前格式为 _H ,但我想要的是类似 ___H .并不是说我希望在我自己的项目中的不同命名空间中有同名的类,但我不想在出现这种情况
每当我从构建中排除 .h 文件并稍后重新包含它时,项目资源管理器中的 .h 文件的图标都会有一个图钉装饰。我查看了 CDT 用户指南,但它不在他们的 list of icons 上。图钉是什么意思?
使用 Eclipse CDT 7.0,在进行 headless 构建时,是否可以指定在命令行上仅构建单个构建配置? 最佳答案 我想我找到了自己问题的答案,主要是通过玩 CDT 8.0 和 indigo
有没有办法在 Eclipse 2020-03 (CDT 9.11) 中启用对 C++20 功能的支持?我的意思是摆脱不正确的语法高亮显示,例如忽略新添加的关键字,如“概念”、“要求”和 C++20 标
我在 Linux 上使用 Eclipse (galileo) 和当前版本的 CDT。而且我不能设置断点!它运行起来很有趣,调试得很好,并在 main 中停止……但是像我多年前用 CDT 那样双击左边距
我最近(实际上是今天)开始使用 Eclipse CDT for windows。创建了一个项目,将一个测试 C 文件(Hello World)添加到项目中。构建项目,出现如下错误。 Error: Pr
我有一个 chroot 环境,其中包含使用 make 构建复杂 C++ 项目所需的一切(适用于特定的 Linux 发行版)。 我想在这个项目中使用 Eclipse CDT(在 chroot 环境之外)
eclipse cdt 如何使用 TM/RSE 管理和构建远程文件??是否有使用 Windows 中的 Eclipse CDT 和 Linux 中的源代码和编译器的项目用法示例? 腾讯 最佳答案 Ta
我正在测试 Eclipse 的 CDT 包。我正在尝试用 C 编译和运行一个简单的 Hello World 程序。 #include int main(void { printf("
大家好, 我已经使用 GCC 安装了 Eclipse CDT 和 MinGW。 将 mingw\bin 添加到我的路径环境变量中。 尝试使用 HelloWorld 向导创建新的 C++ 项目时,出现构
我正在开发 CDT eclipse 插件,我正在尝试使用以下代码使用 CDT 代码获取 eclipse 项目资源管理器中存在的源文件列表,结果为空。 案例1: IFile[] files2 = Res
我是一名优秀的程序员,十分优秀!