| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 775 人关注过本帖
标题:[求助]为什么说unbalanced #endif?
只看楼主 加入收藏
personalbest
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-4-10
收藏
 问题点数:0 回复次数:1 
[求助]为什么说unbalanced #endif?

o4s61QrL.rar (1.32 KB) [求助]为什么说unbalanced #endif?


接口
#ifndef_randword_h
#define_randword_h
#include <stdio.h>
void Initdictionary(FILE* words);
char* ChooseRandomWord(void);
#endif

接口实现
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <randword.h>
char *a[10];
void Initdictionary(FILE *words)
{
int i;
for(i=0;i<=9;i++)
fgets(a[i],20,words);
}

char* ChooseRandomWord(void)
{
srand((int)time(NULL));
return a[rand()%10];
}



主程序
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <randword.h>
main()
{
FILE *infile;
char guess[20];
int chance,len,i,flag,lefts;
char letter;
chance=8;
printf("Welcome to number game\n");
infile=fopen("words.txt","r+");
if(infile==NULL)
{
printf("Find no word.\n");
break;
}
Initdictionary(infile);
guess=ChooseRandomWord();
len=strlen(guess);
lefts=len;
printf("The word now looks like this:");
for(i=0;i<len;i++)
printf("_");
printf("\n");
printf("You have 8 guesses left.\n");
while((chance>0)&&(lefts>0))
{
printf("Guess a letter:");
scanf("%c",letter);
flag=0;
for(i=0;i<len;i++)
{
if(a[i]==letter)
{
printf("That guess is correct.\n");
flag=1;
break;
}
}
if(flag==0)
{
printf("There is no %c in the word\n",letter);
chance--;
}
printf("The word now looks like this:");
for(i=0;i<len;i++)
{
if(a[i]==letter)
{
printf("%c",letter);
lefts--;
}
else
printf("_");
}
printf("\n");
printf("You have %d guesses left.\n",chance);
}
if(chance==0)
printf("You lose.\n");
if(lefts==0)
printf("You win.\n");
}

搜索更多相关主题的帖子: endif unbalanced 
2007-04-12 17:11
personalbest
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-4-10
收藏
得分:0 
牛人们帮忙啊

2007-04-14 20:49
快速回复:[求助]为什么说unbalanced #endif?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020341 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved