Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[2693] 여기서 뭐가틀린건지..오늘안으로 부탁해요..
미니 [] 1137 읽음    2003-05-26 13:21
전에 어떤님이 게시판에 올려놓으신건데 15번 안에 맞추는 행맨 게임이랍니다.. 그런데 해보니깐 3~4번만에 못맞추면 끝나고 중복되는 알파뱃은 하나씩 나오네요...어디가 잘못된거죠? 어떻게 고쳐야하나요..
그리고 gotoxy라는 부분이 있는데 이부분은 금시초문이라.. 이거말고 다른 방법 없나요?(참고로 전 배열과 포인터부분까지밖엔 모르거든요...)

#include<stdio.h>
#include<conio.h>
#include<string.h>

int MatchChar(const char *pWord,char ch,int *matched);

int main(void)
{
const int MaxTrial=15;
const char *const pWord="concatenation";
const int wordLen=strlen(pWord);
int matchedCount=0;
int matchedIndice[16]={0,};
char ch;
int i ,idx;
const int y=wherey();

for(i=1 ;i<=wordLen ;i=i+1){
  putchar('_');
}

printf("\n     : Input a Character. ");

for(i=1 ;i<=MaxTrial ;i=i+1){
  gotoxy(1,y+1);
  printf("%2i/%2i",i,MaxTrial);
  gotoxy(i+26,y+1);
  ch=getche();
  if((idx=MatchChar(pWord,ch,matchedIndice))>=0){
   matchedCount=matchedCount+1;
   gotoxy(idx+1,y);
   putchar(ch);
   if(matchedCount==wordLen) break;
  }else if(wordLen-matchedCount>MaxTrial-i){
   break;
  }
}

gotoxy(1,y+2);
if(matchedCount==wordLen) {
  printf("You Win!");
}else{
  printf("Failed!");
}

getch();
return 0;
}


int MatchChar(const char *pWord,char ch,int *matched)
{
const char *p=pWord;
int index;
if(!pWord || !matched) return -1;
while(1){
  p=strchr(p,ch);
  if(!p) return -1;
  index=p-pWord;
  if(matched[index]==0){
    matched[index]=1;
    return index;
  }else{
   p=p+1;
  }
}
}

+ -

관련 글 리스트
2693 여기서 뭐가틀린건지..오늘안으로 부탁해요.. 미니 1137 2003/05/26
2700     Re:여기서 뭐가틀린건지..오늘안으로 부탁해요.. 임문환.실업자 1191 2003/05/26
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.