- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
<分区>
我似乎无法弄清楚为什么当用户猜完所有字母时我的程序不会结束游戏。我知道问题出在 play() 函数中。关于在播放功能中更改什么或导致此问题的任何内容的任何指示?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
// MAXWORD, which will be the max word length
#define MAXWORD 10
// INCORRECT_GUESSES, which will be the max guesses
#define INCORRECT_GUESSES 5
/* Prototypes */
// Fills theArray with howMany copies of theLetter
void fill_array( char *theArray, int howMany, char theLetter );
// Get char from player, checks the letter, shows progress so far
int get_letter( char *theWord, char *soFar );
// Check if letter is in word, updates progress so far
int letter_in_word( char *theWord, char *soFar, char theLetter );
// Convert the word to lowercase
void lower_string( char *someWord );
// Play one game
void play( char *theWord );
/* Function definitions */
int main( )
{
char theWord [ MAXWORD ];
FILE* word;
word = fopen( "guesswords.txt", "r" );
if ( word == NULL )
{
printf( "No input file found..........\n" );
return -1;
}
printf("Want to play a game?\n");
fscanf( word, "%s", theWord );
lower_string( theWord );
play( theWord );
fprintf( word, "%s", theWord);
fclose( word );
return 0;
}
// Get char from player, checks the letter, shows progress so far
int get_letter( char *theWord, char *soFar )
{
char theLetter;
printf("\nPlease enter a letter: ");
scanf( " %c", &theLetter );
theLetter = tolower(theLetter);
letter_in_word( theWord, soFar, theLetter );
return theLetter;
}
// Fills theArray with howMany copies of theLetter
void fill_array( char *theArray, int howMany, char theLetter )
{
int i;
for( i=0; i<howMany; i++ )
{
theArray[i]= theLetter;
*(theArray + i) = theLetter;
*theArray = theLetter;
}
theArray[howMany] = '\0';
}
// Check if letter is in word, updates progress so far
int letter_in_word( char *theWord, char *soFar, char theLetter )
{
int i;
int num=0;
int len = strlen(theWord);
for( i=0; i<len; i++)
{
if (theWord[i] == theLetter )
{
soFar[i] = theLetter;
num++;
}
}
if (num == 0)
{
printf( "\nSORRY! your letter is not in the word\n" );
printf("%s\n", soFar);
return 0;
}
else if (num>0)
{
printf( "\nCongratz! your letter was in the word\n" );
printf("%s\n", soFar);
return 1;
}
}
// Convert the word to lowercase
void lower_string( char *someWord )
{
int i, cha;
int len = strlen( someWord );
for( i=0; i<len; i++ )
{
cha = someWord[i];
cha = tolower(cha);
someWord[i] = cha;
}
}
// Play one game
void play( char *theWord )
{
int i;
int len = strlen(theWord);
int guess = INCORRECT_GUESSES;
int result = 0;
char soFar[MAXWORD];
fill_array( soFar, len, '*');
printf( "Guess this word: %s\n", soFar );
for( i=0; i<INCORRECT_GUESSES; i++ )
{
guess = INCORRECT_GUESSES - (i+1);
get_letter( theWord, soFar );
if(get_letter<0)
{
printf( "\nYou have %d guesses left\n", guess);
}
else
{
printf( "\nYou have guessed all the letters! You have won!" );
return;
}
if( i == INCORRECT_GUESSES-1)
{
printf( "\nSorry, you're out of guesses\nBetter luck next time!\n" );
}
}
}
编译此静态方法时出现错误,无法找到 int 数组变量 coord。我在方法中声明了它,它的类型是 int[],但我不明白为什么它不起作用。我有一种感觉,这与静态方法有关,但将其更改为静态是我发现使该方
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit th
正如标题所说,您有任何可用资源来开始为 iPhone 进行开发吗? 书籍、在线资源、工具、开发环境、先决条件以及与 iPhone 编程相关的一切都会很好! 谢谢 最佳答案 假设您是初学者,对于书籍而言
我刚刚用Grails创建了一个项目,并通过键入命令来运行它。但是,我最终收到了一条超长的错误消息。 当我用谷歌搜索解决方案时,我碰到了他们正在讨论解决方案的this thread。但是我不知道如何解决
我下面有一个 Json 函数,需要构造一个具有两个函数的类,我的第二个函数如何“知道”作为第一个函数响应的数据 def results(): json_request = reques
作为我的第一个小项目,我正在尝试设置一个测验。我编写了生成问题和答案的方法。我现在试图强制用户输入 1 或 2 来继续循环,而他没有输入。我现在有点迷失了。我是否遗漏了一些非常明显的东西? publi
我对覆盖有疑问。 class base{ public void amethod(){} } class child extends base{ public void amethod(int i){
在 java 程序中,我希望通过调用单个函数来修改 3 个 arraylist 变量。 我是否认为如果我将这 3 个数组列表作为参数传递给该函数,那么所有 3 个都可以在函数内修改?或者我是否必须在单
我终于开始进行单元测试了,因为我知道我应该这样做一段时间,但我有几个问题: 我是否应该重新测试家长测试 children 是否在类里面没有方法被覆盖? 从概念上讲,您如何测试提交了表格的一部分?我在用
我尝试编写一个使用线程的程序,但无法理解 o/p。我有 2 个线程:s 和 t。但我看不到线程 s 正在工作。 有人可以向我解释一下这种行为吗?谢谢 我的代码: public class Bgroun
好吧,我对此还很陌生,我不知道我的代码发生了什么。它看起来是正确的,但是当我尝试运行它时,它给了我除以零的错误? 老师给我的一页上的代码 1: public class Country { /
所以基本上在过去的几天里我一直在努力让这一切顺利进行。我以前有过 Android 开发经验,但没有坚持下去。关于我的内容已经足够了,更多关于应用程序的内容。 很简单,它由4个类组成: Activity
我正在尝试返回一个包含不超过特定数量的所有素数的列表(如果是欧拉计划问题 7)。我对 Python 非常陌生,但我这里的问题似乎不是语言,而是逻辑错误。 import math import sys
我是 libgdx 的初学者,我有一些问题...... 我发现了很多教程,其中一些建议我可以使用 gdx-setup-ui 来生成我的项目,其他建议我可以使用 gdx-setup 来生成我的项目。最好
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关于您编写的代码问题的问题必须在问题本身中描述具体问题 — 并且包括有效代码 以重现它。参见 SSC
我在大学学习编程,我们的任务是创建一个程序,允许用户从计算机中打开文件并从所选文件中获取信息。我的作业的一部分内容如下: 逐行搜索文件中的给定字符串。输出必须包含行号,后跟包含搜索参数的行的内容。例如
所以这是一个位操作练习,我对它们如何将字母转换为数字感到困惑,我认为这些不是二进制的,所以我不知道它们是什么意思。任何人都可以建议一种方法吗? Here's two examples of encry
我正在麻省理工学院 OCW 介绍 C++,下面的代码在教授的第一个问题集中给出,作为计算阶乘的基本程序,还有一些相关问题。 #include using std::cout; using std::
到目前为止,我一直在尝试通过在我的项目中立即实现线程来掌握线程。很长一段时间以来,我一直在努力做到这一点。但这并没有产生任何结果,也没有给我任何线程方面的经验。这次尝试给我的唯一印象是 C# 中的线程
我必须为我所有关于 rails 的帖子做序:我是新手。 是否有必要为我的应用程序编写测试以使其正常工作,还是严格用于查找中断? 最佳答案 测试您的应用程序并不是让它工作所必需的,但强烈建议您这样做并且
我是一名优秀的程序员,十分优秀!