我不是编程方面的超级初学者,但我对通过windows命令提示符窗口编译和运行代码相对来说还是比较新的。
#include <stdio.h>
int main(){
double LATER = 0, EARLIER = 0, RESULT = 0; // Declare and initialize LATER and EARLIER
//to store operands and RESULT to hold a
//calculated result. Declare as type double.
char COMMAND = ' '; // Declare COMMAND to store the last entered character.
return 0;}
/*
while !(COMMAND == 'q')
{
printf("Please enter operand(s), and/or an operator. \n (For division and subtraction, ensure that the numerator or minuend is entered first): \n");
scanf("%lf %lf %c \n",&EARLIER,&LATER,&OPERATOR); // Read in large float values for EARLIER and LATER and a character value for OPERAND
printf("= %.3lf", RESULT);
}
*/每当我编译这个(GCC)并尝试运行它时,我的命令提示符就会结冰--也就是说,它不接受任何输入,只是停留在一个黑色的屏幕上(先前的控制台输出仍然显示)。有人知道我该怎么做才能解决这个问题吗?
Update:尝试从CodeBlocks运行相同的东西,并且遇到了同样的问题。两个控制台窗口弹出,一个运行代码并关闭,另一个停留在周围,无法关闭。如果不重新启动,仍然无法再次运行该程序。
发布于 2015-03-08 10:24:04
问得好。我坚信这是GCC win32中的一个bug (在我的例子中是MinGW),尽管细节很难确定,所以我不确定是否有关于它的现有bug报告,或者我在这里引用它。它似乎影响很少的人,因为我没有看到它在其他地方提及。
release I有一个正在运行的复杂应用程序,我已经开发了一段时间;但是有时候,即使进行了一些微小的增量更改(一行,没有错误),GCC也会锁定命令提示符(具有管理权限),这有时可以关闭,而其他时候,关闭按钮、任务管理器或Windows关机都不能释放进程;尝试在另一个命令提示符中运行GCC也同样失败。然后我必须强制重启。在重新启动之后,一定已经清除了某种缓存或gcc应用程序状态,因为编译会顺利进行。gcc -v返回:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=m
ingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto
--enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++
,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-l
ibstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gm
p-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --
with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-
libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/
mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)P.S.根据this question的说法,GCC可能被锁在内核资源上。这可能是因为它试图访问Windows内核资源与Linux的方式,而Linux是从后者移植的。
P.P.S.,如果这不是GCC的错误,那么OP和我有一些共同的操作系统问题。
发布于 2014-04-06 12:11:53
问题中的代码很简单:
double变量LATER、EARLIER和RESULT。0。char变量COMMAND。0)因此,您可以看到是一个空控制台。
查看相同代码的正确缩进列表。请注意,main()函数以return 0;后面的行结尾,该行之后的所有内容都是多行注释,输出二进制文件中不生成可执行指令。
#include <stdio.h>
int main()
{
double LATER = 0, EARLIER = 0, RESULT = 0;
// Declare and initialize LATER and EARLIER
//to store operands and RESULT to hold a
//calculated result. Declare as type double.
// Declare COMMAND to store the last entered character.
char COMMAND = ' ';
return 0;
}
/*
while !(COMMAND == 'q') {
printf("Please enter operand(s), and/or an operator. \n"
"(For division and subtraction,"
" ensure that the numerator or minuend is entered first):");
// Read in large float values for EARLIER and LATER and a character value for OPERAND
scanf("%lf %lf %c \n",&EARLIER,&LATER,&OPERATOR);
printf("= %.3lf", RESULT);
}
*/您需要沿着以下代码行执行一些操作,这些代码:
q“字符,则退出,否则再次请求3个输入。缺少Step2的代码。这是你的TODO ;-)
#include <stdio.h>
int main()
{
// Declare and initialize LATER and EARLIER
//to store operands and RESULT to hold a
//calculated result. Declare as type double.
double earlier = 0, later = 0, result = 0;
// Declare COMMAND to store the last entered character.
char cmd = ' ';
while (cmd != 'q') {
printf("Please enter the following 3\n"
"< operand1 operand2 operator >\n"
"(For division and subtraction,"
" ensure that the numerator or minuend is entered first):\n");
// Read in large float values for EARLIER and LATER and a character value for OPERAND
scanf("%lf %lf %c", &earlier, &later, &cmd);
// TODO: Add code to calculate "result" here
// Print "result"
printf("result= %.3lf\n", result);
}
return 0;
}https://stackoverflow.com/questions/21668086
复制相似问题