- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
编译我的 Dice Roll 程序后,出现此错误。代码有什么问题?
也在我使用 gets() 而不是 scanf() 命令之前,但因此我收到了此错误 - 传递“gets”的参数 1 使指针来自整数而不进行强制转换所以我删除了 gets() 命令并使用了 scanf,然后就没有关于 scanf() 的错误了。
出现这两个错误的原因是什么?
<小时/>好的,根据答案,我知道应该如何使用 gets() 命令以及为什么我不应该使用它而应该使用 scanf()。所以,我做出了改变。虽然我遇到了两个新错误,但这一次与我使用的delay()命令有关。
错误:未定义的延迟引用 |错误:ld 返回 1 退出状态|
<小时/>好的,我通过使用 windows.h 库中的 Sleep() 命令而不是 Delay() 命令解决了我最后的错误。程序已编译。但程序中仍然存在运行时错误,它在获得 roll1 之前运行良好,但随后它只打印接下来的两条语句并终止程序,而不接受猜测的输入。
它会跳过 printf("Will it be Higher/Lower or the same? (press H/L/S)\n");
之后的所有代码并直接终止程序。
好的,所以我解决了上述问题,在 "%c"
之前添加了一个空格。在scanf(" %c", &nextGuess);
陈述。 (小事xD)现在唯一的问题是我的toupper()
命令不起作用。
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <windows.h>
int main()
{
int i, roll1=0, roll2=0, NumberOfRolls, RandomNUM1[50], RandomNUM2[50];
char nextGuess;
puts("Welcome to the Dice Roll Game");
puts("How many times do you want to roll a dice?");
scanf("%d", &NumberOfRolls);
for( i=1; i<=NumberOfRolls; i++ ) {
RandomNUM1[i] = ( rand()%6 ) + 1;
roll1 += RandomNUM1[i];
}
printf("\nYou Got %d in your first roll!\n", roll1);
Sleep(3000);
printf("\nLet's see if you can guess the value of next roll.\n");
printf("Will it be Higher/Lower or the same? (press H/L/S)\n");
scanf(" %c", &nextGuess);
toupper(nextGuess);
for( i=1; i<=NumberOfRolls; i++ ) {
RandomNUM2[i] = ( rand()%6 ) + 1;
roll2 += RandomNUM2[i];
}
if(nextGuess=='H'){
if(roll1<roll2){
printf("You are such a player, you guessed it right! It's %d", roll2);
}
else if(roll1>roll2){
printf("Uh-Oh! Bad Luck! First roll was higher, It's %d", roll2);
}
else if(roll1==roll2){
printf("Uh-Oh! Bad Luck! Both the rolls are same, It's %d", roll2);
}
}
if(nextGuess=='L'){
if(roll1>roll2){
printf("You are such a player, you guessed it right! It's %d", roll2);
}
else if(roll1<roll2){
printf("Uh-Oh! Bad Luck! First roll was lower, It's %d", roll2);
}
else if(roll1==roll2){
printf("Uh-Oh! Bad Luck! Both the rolls are same, It's %d", roll2);
}
}
if(nextGuess=='S'){
if(roll1==roll2){
printf("You are such a player, you guessed it right! It's %d", roll2);
}
else if(roll1>roll2){
printf("Uh-Oh! Bad Luck! First roll was higher, It's %d", roll2);
}
else if(roll1<roll2){
printf("Uh-Oh! Bad Luck! Second roll is higher, It's %d", roll2);
}
}
return 0;
}
最佳答案
你有一个流浪,
在main
的第二行,声明char nextGuess,
而不是char nextGuess;
编译器告诉您它需要在 ,
之后添加说明符或 ...,因此您可以添加这些说明符,或者使用 ;
正确结束该行。
对于你提到的另一个问题:
passing argument 1 of 'gets' makes pointer from integer without a cast
因为 gets
参数应该是 char *str
而您没有提供它。
您可以通过以下方式解决该问题:
char tmp_NumberOfRolls[10];
gets(tmp_NumberOfRolls);
NumberOfRolls = atoi(tmp_NumberOfRolls);
但我更喜欢 scanf
解决方案
PS:(在现在编辑的代码版本中)***//Error Line***
不是注释(至少不是全部)它),因为 ***
仍然被算作代码的一部分,并且会导致错误。将 //
向左移动一点,或者用 /* ... */
关于c - 错误: expected declaration specifiers or '...' before string constant [puts() and gets() statement errors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45127682/
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我是脚本新手。如何编写 Expect 脚本以通过 ssh 连接到设备并提示用户输入密码?我们使用 pin + RSA token 代码作为密码,因此我无法存储密码。 #!/usr/bin/expect
我编写了以下代码并尝试执行它。但我在执行 do {”时遇到“无效的命令名称“do”” 代码: #!/usr/bin/expect set val 0; set input 5; do { pu
我已经查看了 Expect 联机帮助页并用 Google 搜索了它,但我还没有找到 expect 的 -r 是什么。我看到这个选项以前是这样用的 expect -r "\r\n\r\n" 在 expe
我的 shebang 看起来像这样: #!/usr/bin/expect -d 当我从命令行运行脚本时,它会提供我想要的内容。 但是,我通过 crontab 运行这个脚本。是否可以将调试开关保持打开状
我是 Expect 脚本的新手。 我在 Linux 机器上为 ssh 编写了一个 Expect 脚本,在那里我在 ssh 到不同的 Linux 机器时遇到了问题。下面我复制了脚本。 !/usr/loc
Scene 1, Layer 'script', Frame 1, Line 9 1084: Syntax error: expecting identifier before this. Sc
我正在运行调试命令以将命令的输出记录到文件中。我尝试了 log_file 命令,但它没有记录输出。我的代码如下: log_file -a gdb.txt send "~/debugulator.sh
我希望 expect_user 有一个无限的(或非常大的)超时和 expect 的默认超时。有没有办法设置不同的超时?或者我是否只需要在每次更改用途之前手动执行此操作? 最佳答案 expect 和ex
我正在学习 iOS 编程(我来自 Android),我正在寻找更容易获取字符串的方法。有了这个建议,我定义了下一个宏并在一些代码片段中使用它: #define STRING_BASE @"InfoPl
你好我是 rspec 的新手,我想弄清楚将 block 传递给 expect{} 和只使用 expect() 之间的区别 这是一个简单的例子 require "rails_helper" RSpec.
我正在尝试为 React JS 运行单元测试 - 使用 jest/enzyme。 目前测试失败。不太清楚为什么,也许我没有正确调用 expect(wrapper.find)。这是我测试的一部分: F
例如,现在我有一个“root.exp”期望脚本如下: spawn ssh user@ip expect "Password:" send "password" 然后,我要发送到这个ssh服务器的exp
您好,我是 Expect 脚本编写的新手,我一直在尝试使用以下方法将 IP 地址获取到变量中: set timeout -1 spawn $env(SHELL) match_max 100000 se
expect.anything() 不适用于 expect.toBe(),但适用于 expect.toEqual() test("this will pass", () => { expect("
我有一个如下所示的简单脚本,从命令行读取 2 个数字并将它们加在一起: $cat runexp.sh #!/bin/bash echo "read 1st number" read n1 echo "
当 Linux 机器的 $IP 登录后询问密码时,下面的 expect 脚本工作正常 但在某些情况下,某些Linux机器不需要ssh密码(我们可以不用密码登录), 所以我需要更改我的期望脚本以支持没有
我正在尝试使用 expect 远程登录服务器并更改用户密码。该应用程序要求,如果您要更改的密码包含特殊字符,则将其引用。问题是,还需要引用 expect send 语句,当我尝试将两者结合起来时,脚本
下面这个简单的 expect 脚本的目标是获取远程机器上的 hostname 名称 有时期望脚本无法执行到 $IP_ADDRESS 的 ssh(因为远程机器不活动等) 所以在这种情况下,expect
我试图创建一个宏来替换, first: Some(first.as_ref().parse::().expect("Could not parse 'first'")) 我在其他模块(如 Clap w
我是一名优秀的程序员,十分优秀!