void searchResult(UserInfo userInfo[], int num) { int input; resultSound(); while (1){ topMessage("검색", "Search"); messageBoxB("검색 ", "결과"); printf("\n\n\t\t\t회원ID\t: %d \n\n", userInfo[num].userId); printf("\t\t\t이름\t: %s \n", userInfo[num].userName); printf("\t\t\t연락처\t: %s \n", userInfo[num].handphone); printf("\t\t\t주소\t: %s \n", userInfo[num].userAddress); puts("\n\n"); BOT_COLOR; printf("\t\t\t\t\t\t\t\t\t "); printf("\t\t\t\t 나가기 : ESC \t\t\t\t\t "); printf("\t\t\t\t\t\t\t\t\t "); DEF_COLOR; input = getch(); if (input == ESC_KEY){ outSound(); return; } else warningMessage(input - '0', 0, 0); } }
void searchMain(UserInfo userInfo[], int todo, char mess[], char top[]) { int input, menu = 1, num; int *ptr = &menu; char *menu_num2[MENU_NUM] = { { "1. 회원ID로 검색" }, { "2. 이름으로 검색" }, { "3. 연락처로 검색" } }; while (1) { topMessage(mess, top); messageBoxB("검색 ", "방법"); menuSelectB(menu, 3, menu_num2); bottomMessageC(); input = getch(); if (input == ARROW_BUFFER) input = getch(); switch (input) { case UP_ARROW_KEY: moveSound(); if (menu > 1) menu--; break; case DOWN_ARROW_KEY: moveSound(); if (menu < 3) menu++; break; case ENTER_KEY: inSound(); num = searchUser(userInfo, menu); if (num){ if (todo == _DELETE) deleteUser(userInfo, num); else if (todo == MODIFY) modifyUser(userInfo, num); else searchResult(userInfo, num); } break; case ESC_KEY: outSound(); return; default: warningMessage(input - '0', 3, ptr); break; } } }
void deleteUser(UserInfo userInfo[], int del) { int input, menu = 1; while (del){ topMessage("삭제", "Delete"); printf("\n\n\n\n\t\t\t회원ID\t: %d \n\n", userInfo[del].userId); printf("\t\t\t이름\t: %s \n", userInfo[del].userName); printf("\t\t\t연락처\t: %s \n", userInfo[del].handphone); printf("\t\t\t주소\t: %s \n", userInfo[del].userAddress); puts("\n\n\n\t\t\t 정말로 삭제하시겠습니까? \n\n\n"); bottomMessageB("삭제"); input = getch(); if (input == ENTER_KEY){ inSound(); /* 빈 메모리 공간이 많아지면 메모리 할당량 축소 */ if (count < maxsize / 3){ maxsize /= 2; userInfo = (UserInfo*)realloc(userInfo, sizeof(UserInfo)*maxsize); } /* 삭제 대상이 맨 마지막에 있다면, count를 하나 줄이는 것으로 끝 */ if (del == count){ centerMessage("삭제", "Delete"); count--; return; } /* 나머지 경우는 한 칸씩 앞으로 덮어씌움 */ else{ for (int i = del + 1; i <= count; i++){ userInfo[i - 1].userId = userInfo[i].userId; strcpy(userInfo[i - 1].userName, userInfo[i].userName); strcpy(userInfo[i - 1].userAddress, userInfo[i].userAddress); strcpy(userInfo[i - 1].handphone, userInfo[i].handphone); } centerMessage("삭제", "Delete"); count--; return; } } else if (input == ESC_KEY){ outSound(); return; } else warningMessage(input - '0', 0, 0); } return; }
int searchManyPrint(UserInfo userInfo[], int overlap[], int num) { int input; resultSound(); while (1) { topMessage("검색", "Search"); BEAUTI2_COLOR; puts("\n\t\t\t ◎ 검색 결과 ◎"); BEAUTI1_COLOR; puts("\t\t\t ================"); DEF_COLOR; for (int i = 1; i <= num; i++){ printf(" %2d. %d \t %s \t%s \t%s\n", i, userInfo[overlap[i]].userId, userInfo[overlap[i]].userName, userInfo[overlap[i]].handphone, userInfo[overlap[i]].userAddress); } for (int i = 1; i < OVERLAP_BUFFER - num; i++) puts(" "); //공백 채우기 if (num + 1 == OVERLAP_BUFFER){ BEAUTI2_COLOR; puts("\n\t\t 검색 결과가 더 있으나 여기까지만 출력됩니다. "); puts("\t\t원하시는 결과가 없으면 다른 방법으로 검색해주세요.\n"); } else puts("\n\n\n"); BOT_COLOR; printf("\t\t\t\t\t\t\t\t\t "); printf("\t 선택 : 해당 번호 입력 \t\t 나가기 : ESC \t\t "); printf("\t\t\t\t\t\t\t\t\t "); DEF_COLOR; input = getch(); input -= '0'; //아스키 값을 받기 때문에 if (input + '0' == ESC_KEY){ outSound(); return 0; } else if (input > 0 && input <= num){ inSound(); return overlap[input]; } else warningMessage(input - '0', 0, 0); } }
void printList(UserInfo userInfo[]) { int input, page, k = 1, temp; int *ptr = &k; char search[OVERLAP_BUFFER]; page = 1 + (count - 1) / 18; //전체 페이지 계산 while(1) { printListSub(userInfo, page, ptr, ON); input = getch(); if (input == ARROW_BUFFER) input = getch(); switch (input) { case LEFT_ARROW_KEY: //좌측 방향키 moveSound(); if (k != 1) k--; break; case RIGHT_ARROW_KEY: //우측 방향키 moveSound(); if (k != page) k++; break; case ENTER_KEY: //enter키 inSound(); printListSub(userInfo, page, ptr, OFF); printf("페이지 검색: "); fgets(search, OVERLAP_BUFFER, stdin); temp = atoi(search); if (temp > 0 && temp <= page) k = temp; else warningMessage(0, 0, 0); break; case ESC_KEY: //esc키 outSound(); return; default: warningMessage(input - '0', page, ptr); break; } } }
int saveInfo(UserInfo userInfo[], FILE *writeFile) { int input; while (1) { system("cls"); TOP_COLOR; printf("Save \t\t\t\t\t\t\t\t\t\t"); printf("\t\t\t\t\t\t\t\t\t "); BOT_COLOR; printf("\t\t\t\t\t\t\t\t\t "); printf("\t\t\t 변경 내용 저장\t\t\t\t\t "); printf("\t\t\t\t\t\t\t\t\t "); DEF_COLOR; puts("\n\n\n\n\n\n\n\n\t\t\t 정말로 저장하시겠습니까? \n\n\n\n\n\n\n"); bottomMessageB("저장"); input = getch(); if (input == ENTER_KEY){ actionSound(); writeFile = fopen("data.txt", "wt"); //writeFile open fprintf(writeFile, "%s\n", userInfo[0].userAddress); for (int i = 1; i <= count; i++) fprintf(writeFile, "%d\t%s\t%s\t%s\n", userInfo[i].userId, userInfo[i].userName, userInfo[i].userAddress, userInfo[i].handphone); fclose(writeFile); //writeFile close return SAVE; } else if (input == ESC_KEY){ outSound(); return 0; } else warningMessage(input - '0', 0, 0); } }
int main() { std::srand(static_cast<unsigned int>(std::time(NULL))); // Define some constants const float pi = 3.14159f; const int gameWidth = 800; const int gameHeight = 600; sf::Vector2f paddleSize(25, 100); float ballRadius = 10.f; bool easyMode = true; bool hardMode = false; // create the window sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight), "Dizzy Pong"); // set a view sf::View view = window.getDefaultView(); view.zoom(2.f); window.setView(view); float rVal = 0.005; // Load the sounds used in the game sf::SoundBuffer ballSoundBuffer; if (!ballSoundBuffer.loadFromFile("resources/ball.wav")) return EXIT_FAILURE; sf::Sound ballSound(ballSoundBuffer); sf::SoundBuffer outSoundBuffer; if (!outSoundBuffer.loadFromFile("resources/boxing_bell.wav")) return EXIT_FAILURE; sf::Sound outSound(outSoundBuffer); // set up text sf::Text text; int textXpos = 0; int textYpos = 0; int textSize = 44; sf::Color textColor = sf::Color::White; sf::Font font; if (!font.loadFromFile("resources/sansation.ttf")) return EXIT_FAILURE; text.setFont(font); text.setString("Hello!"); text.setCharacterSize(textSize); text.setColor(textColor); text.setPosition(textXpos, textYpos); sf::Text pauseMessage; pauseMessage.setFont(font); pauseMessage.setString("Welcome to SFML pong!\nPress space to start the game"); pauseMessage.setCharacterSize(textSize); pauseMessage.setColor(textColor); pauseMessage.setPosition(170.f, 150.f); sf::Text toggleInstruct; toggleInstruct.setFont(font); toggleInstruct.setString("Press h to toggle hard mode"); toggleInstruct.setCharacterSize(textSize*.8); toggleInstruct.setColor(textColor); toggleInstruct.setPosition(gameWidth / 3, gameHeight - 50); sf::Text playerScore; int pScore = 0; playerScore.setFont(font); playerScore.setString(std::to_string(pScore)); playerScore.setCharacterSize(textSize); playerScore.setColor(textColor); playerScore.setPosition(170.f, 150.f); sf::Text compScore; int cScore = 0; compScore.setFont(font); compScore.setString(std::to_string(cScore)); compScore.setCharacterSize(textSize); compScore.setColor(textColor); compScore.setPosition(370.f, 150.f); //set up visual boundaries sf::Vector2f boundSize(gameWidth, gameHeight); sf::RectangleShape boundary(boundSize); boundary.setFillColor(sf::Color::Black); boundary.setOutlineColor(sf::Color::White); boundary.setOutlineThickness(10); sf::Color boundColor; if (easyMode) boundColor = sf::Color::Red; else boundColor = sf::Color::Black; sf::RectangleShape leftBound(sf::Vector2f(15, gameHeight)); leftBound.setPosition(sf::Vector2f(-15, 0)); leftBound.setFillColor(boundColor); sf::RectangleShape rightBound(sf::Vector2f(15, gameHeight)); rightBound.setPosition(gameWidth, 0); rightBound.setFillColor(boundColor); //set up left paddle sf::Vector2f paddlePosL(10 + paddleSize.x / 2, gameHeight / 2); Paddle leftPaddle = Paddle::Paddle(paddleSize, sf::Color::White, paddlePosL); //set up right paddle sf::Vector2f paddlePosR((gameWidth-10)-paddleSize.x/2, gameHeight / 2); Paddle rightPaddle = Paddle::Paddle(paddleSize, sf::Color::White, paddlePosR); //set up ball Ball ball = Ball::Ball(ballRadius); // Define the paddles properties sf::Clock AITimer; const sf::Time AITime = sf::seconds(0.1f); const float paddleSpeed = 400.f; float rightPaddleSpeed = 0.f; const float ballSpeed = 400.f; float ballAngle = 0.f; // to be changed later sf::Clock clock; bool isPlaying = false; bool newRound = true; // run the program as long as the window is open while (window.isOpen()) { // check all the window's events that were triggered since the last iteration of the loop sf::Event event; while (window.pollEvent(event)) { // Window closed or escape key pressed: exit if ((event.type == sf::Event::Closed) || ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))) { window.close(); break; } // h key pressed: toggle hardMode if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::H)) { hardMode = !hardMode; if (hardMode) boundColor = sf::Color::Black; else if (!hardMode) boundColor = sf::Color::Red; leftBound.setFillColor(boundColor); rightBound.setFillColor(boundColor); } // Space key pressed: play if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space)) { if (!isPlaying) { // (re)start the game isPlaying = true; clock.restart(); // Reset the position of the paddles and ball leftPaddle.paddle.setPosition(10 + paddleSize.x / 2, gameHeight / 2); rightPaddle.paddle.setPosition(gameWidth - 10 - paddleSize.x / 2, gameHeight / 2); ball.ball.setPosition(gameWidth / 2, gameHeight / 2); // Reset the ball angle do { // Make sure the ball initial angle is not too much vertical ballAngle = (std::rand() % 360) * 2 * pi / 360; } while (std::abs(std::cos(ballAngle)) < 0.7f); } } } if (isPlaying) { float deltaTime = clock.restart().asSeconds(); if (newRound){ // Reset the position of the paddles and ball leftPaddle.paddle.setPosition(10 + paddleSize.x / 2, gameHeight / 2); rightPaddle.paddle.setPosition(gameWidth - 10 - paddleSize.x / 2, gameHeight / 2); ball.ball.setPosition(gameWidth / 2, gameHeight / 2); // Reset the ball angle do { // Make sure the ball initial angle is not too much vertical ballAngle = (std::rand() % 360) * 2 * pi / 360; } while (std::abs(std::cos(ballAngle)) < 0.7f); newRound = false; } // Move the player's paddle if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && (leftPaddle.paddle.getPosition().y - paddleSize.y / 2 > 5.f)) { leftPaddle.paddle.move(0.f, -paddleSpeed * deltaTime); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && (leftPaddle.paddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f)) { leftPaddle.paddle.move(0.f, paddleSpeed * deltaTime); } // Move the computer's paddle if (((rightPaddleSpeed < 0.f) && (rightPaddle.paddle.getPosition().y - paddleSize.y / 2 > 5.f)) || ((rightPaddleSpeed > 0.f) && (rightPaddle.paddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f))) { rightPaddle.paddle.move(0.f, rightPaddleSpeed * deltaTime); } // Update the computer's paddle direction according to the ball position if (AITimer.getElapsedTime() > AITime) { AITimer.restart(); if (ball.ball.getPosition().y + ballRadius > rightPaddle.paddle.getPosition().y + paddleSize.y / 2) rightPaddleSpeed = paddleSpeed; else if (ball.ball.getPosition().y - ballRadius < rightPaddle.paddle.getPosition().y - paddleSize.y / 2) rightPaddleSpeed = -paddleSpeed; else rightPaddleSpeed = 0.f; } // Move the ball float factor = ballSpeed * deltaTime; ball.ball.move(std::cos(ballAngle) * factor, std::sin(ballAngle) * factor); // Check collisions between the ball and the screen //offscreen, play out sound if (ball.ball.getPosition().x - ballRadius < 0.f) { outSound.play(); if (cScore >= 3) { isPlaying = false; pauseMessage.setString("You lost!\nPress space to restart or\nescape to exit"); cScore = 0; pScore = 0; compScore.setString(std::to_string(cScore)); playerScore.setString(std::to_string(pScore)); newRound = true; rVal = 0; } else{ cScore = cScore + 1; compScore.setString(std::to_string(cScore)); newRound = true; if (!hardMode) rVal = 0; //pauseMessage.setString("You lost!\nPress space to restart or\nescape to exit"); } } if (ball.ball.getPosition().x + ballRadius > gameWidth) { outSound.play(); if (pScore >= 3) { isPlaying = false; pauseMessage.setString("You won!\nPress space to restart or\nescape to exit"); pScore = 0; cScore = 0; compScore.setString(std::to_string(cScore)); playerScore.setString(std::to_string(pScore)); newRound = true; rVal = 0; } else{ pScore++; playerScore.setString(std::to_string(pScore)); newRound = false; if (!hardMode) rVal = 0; //pauseMessage.setString("You won!\nPress space to restart or\nescape to exit"); } } //collisions with walls, play bounce sound if (ball.ball.getPosition().y - ballRadius < 0.f) { ballSound.play(); ballAngle = -ballAngle; ball.ball.setPosition(ball.ball.getPosition().x, ballRadius + 0.1f); } if (ball.ball.getPosition().y + ballRadius > gameHeight) { ballSound.play(); ballAngle = -ballAngle; ball.ball.setPosition(ball.ball.getPosition().x, gameHeight - ballRadius - 0.1f); } // Check the collisions between the ball and the paddles // Left Paddle if (ball.ball.getPosition().x - ballRadius < leftPaddle.paddle.getPosition().x + paddleSize.x / 2 && ball.ball.getPosition().x - ballRadius > leftPaddle.paddle.getPosition().x && ball.ball.getPosition().y + ballRadius >= leftPaddle.paddle.getPosition().y - paddleSize.y / 2 && ball.ball.getPosition().y - ballRadius <= leftPaddle.paddle.getPosition().y + paddleSize.y / 2) { if (ball.ball.getPosition().y > leftPaddle.paddle.getPosition().y) ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180; else ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180; ballSound.play(); ball.ball.setPosition(leftPaddle.paddle.getPosition().x + ballRadius + paddleSize.x / 2 + 0.1f, ball.ball.getPosition().y); if (!hardMode) rVal += .003; } // Right Paddle if (ball.ball.getPosition().x + ballRadius > rightPaddle.paddle.getPosition().x - paddleSize.x / 2 && ball.ball.getPosition().x + ballRadius < rightPaddle.paddle.getPosition().x && ball.ball.getPosition().y + ballRadius >= rightPaddle.paddle.getPosition().y - paddleSize.y / 2 && ball.ball.getPosition().y - ballRadius <= rightPaddle.paddle.getPosition().y + paddleSize.y / 2) { if (ball.ball.getPosition().y > rightPaddle.paddle.getPosition().y) ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180; else ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180; ballSound.play(); ball.ball.setPosition(rightPaddle.paddle.getPosition().x - ballRadius - paddleSize.x / 2 - 0.1f, ball.ball.getPosition().y); if (!hardMode) rVal += .003; } } // clear the window with black color window.clear(sf::Color::Black); // draw boundaries window.draw(boundary); window.draw(leftBound); window.draw(rightBound); if (isPlaying) { //roatate the view if (hardMode) rVal += 0.000001; view.rotate(rVal); window.setView(view); // Draw the paddles, score, and the ball window.draw(leftPaddle.paddle); window.draw(rightPaddle.paddle); window.draw(playerScore); window.draw(compScore); window.draw(ball.ball); } else { // Draw the pause message if (newRound){ view.setRotation(0); window.setView(view); window.draw(pauseMessage); window.draw(toggleInstruct); } } // end the current frame window.display(); } return 0; }
int dataInputB(UserInfo userInfo[], int switB, char *temp, int fix, char str[], int min, int max) { int input, warning = 0, action = 1, switC = 1, switD = 1; int *ptrC; ptrC = &switC; while (1) { topMessage("수정", "Modify"); messageBoxB(str, "수정"); switch (switB){ case NAME: printf("\n\t\t 기존 %s : %s \n", str, userInfo[fix].userName); break; case ADDRESS: printf("\n\t\t 기존 %s : %s \n", str, userInfo[fix].userAddress); break; case PHONE: printf("\n\t\t 기존 %s : %s \n", str, userInfo[fix].handphone); break; } printf("\t\t 새로운 %s : ", str); if (action){ switC = switB; warning = dataInputAction(warning, switB, ptrC, temp, min, max); } else printf("%s \n", temp); if(warning){ dataInputWarning(temp, MODIFY, switB, switC); input = getch(); if (input == ESC_KEY){ outSound(); return 0; //취소시 0을 리턴 } else if (input == ENTER_KEY){ inSound(); action = 1; } else{ action = 0; warningMessage(input - '0', 0, 0); } } else{ puts("\n\n\n\t\t\t 정말로 수정하시겠습니까? \n\n\n"); bottomMessageB("수정"); input = getch(); if (input == ENTER_KEY){ inSound(); return 1; //수정하면 1반환 } else if (input == ESC_KEY){ outSound(); return 0; } else{ action = 0; warningMessage(input - '0', 0, 0); } } } }
void dataInputA(UserInfo userInfo[]) { int input, warning = 0, action = 1, switC = 1, switD = 1; int *ptrC = &switC; while (1) { topMessage("입력", "Regist"); printf("\n\n\n\n\t\t\t 회원ID\t: "); BEAUTI3_COLOR; printf("%d \n\n", userInfo[count].userId); DEF_COLOR; if (switD == 1){ for (int i = 0; i < NAME_PHONE_BUFFER; i++) userInfo[count].userName[i] = 0; } else if (switD == 2){ for (int i = 0; i < NAME_PHONE_BUFFER; i++) userInfo[count].handphone[i] = 0; } else if (switD == 3){ for (int i = 0; i < ADDRESS_BUFFER; i++) userInfo[count].userAddress[i] = 0; } if (switD == 1 && action){ BEAUTI2_COLOR; printf("\t\t\t 이름\t: "); BEAUTI1_COLOR; switC = NAME; warning = dataInputAction(warning, NAME, ptrC, userInfo[count].userName, 4, 8); if (!warning){ switD = 2; continue; } } else if (switD >= 1){ printf("\t\t\t 이름\t: "); BEAUTI3_COLOR; printf("%s \n", userInfo[count].userName); DEF_COLOR; } if (switD == 2 && action){; BEAUTI2_COLOR; printf("\t\t\t 연락처\t: "); BEAUTI1_COLOR; switC = PHONE; warning = dataInputAction(warning, PHONE, ptrC, userInfo[count].handphone, 11, 13); if (!warning){ switD = 3; continue; } } else if (switD >= 2){ printf("\t\t\t 연락처\t: "); BEAUTI3_COLOR; printf("%s \n", userInfo[count].handphone); DEF_COLOR; } if (switD == 3 && action){ BEAUTI2_COLOR; printf("\t\t\t 주소\t: "); BEAUTI1_COLOR; switC = ADDRESS; warning = dataInputAction(warning, ADDRESS, ptrC, userInfo[count].userAddress, 10, 30); if (!warning){ switD = 4; continue; } } else if (switD >= 3){ printf("\t\t\t 주소\t: "); BEAUTI3_COLOR; printf("%s \n", userInfo[count].userAddress); DEF_COLOR; } if (warning){ dataInputWarning((char*)0, INSERT, 0, switC); input = getch(); if (input == ESC_KEY){ maxid--; count--; //등록하지 않으면 count 원래대로 되돌려 놓고 종료 outSound(); return; } else if (input == ENTER_KEY){ action = 1; inSound(); } else{ action = 0; warningMessage(input - '0', 0, 0); } } else{ puts("\n\n\n\t\t\t 정말로 등록하시겠습니까? \n\n\n"); bottomMessageB("등록"); input = getch(); if (input == ESC_KEY){ maxid--; count--; outSound(); return; } else if (input == ENTER_KEY){ actionSound(); Beep(_DO, DURATION); return; //등록하면 count 증가한 채로 종료 } else{ action = 0; warningMessage(input - '0', 0, 0); } } } }
void modifyUser(UserInfo userInfo[], int fix) { int input, menu = 1, action, action2; char temp[ADDRESS_BUFFER]; char *ptr; int *ptr2; ptr = temp; ptr2 = &menu; action = 1; char *menu_num3[MENU_NUM] = { { "1. 이름" }, { "2. 주소" }, { "3. 연락처" }, }; inSound(); while (action){ topMessage("수정", "Modify"); messageBoxA(" 수정할 정보 "); menuSelectC(menu, 3, menu_num3); bottomMessageC(); input = getch(); if (input == ARROW_BUFFER) input = getch(); switch (input) { case UP_ARROW_KEY: moveSound(); if (menu > 1) menu--; break; case DOWN_ARROW_KEY: moveSound(); if (menu < 3) menu++; break; case ENTER_KEY: inSound(); switch (menu){ case NAME: action2 = dataInputB(userInfo, NAME, ptr, fix, "이름 ", 4, 8); if (action2){ strcpy(userInfo[fix].userName, temp); centerMessage("수정", "Modify"); } break; case ADDRESS: action2 = dataInputB(userInfo, ADDRESS, ptr, fix, "주소 ", 10, 30); if (action2){ strcpy(userInfo[fix].userAddress, temp); centerMessage("수정", "Modify"); } break; case PHONE: action2 = dataInputB(userInfo, PHONE, ptr, fix, "연락처", 12, 13); if (action2){ strcpy(userInfo[fix].handphone, temp); centerMessage("수정", "Modify"); } break; } break; case ESC_KEY: action = 0; outSound(); break; default: warningMessage(input - '0', 3, ptr2); break; } } }
int closeProgram(void) { int input, menu = 1; while (1) { system("cls"); TOP_COLOR; printf("Close \t\t\t\t\t\t\t\t\t\t"); printf("\t\t\t\t\t\t\t\t\t "); BOT_COLOR; printf("\t\t\t\t\t\t\t\t\t "); printf("\t\t\t 프로그램 종료 \t\t\t\t\t "); printf("\t\t\t\t\t\t\t\t\t "); DEF_COLOR; printf("\n\n\n\n\t\t\t "); BOX_COLOR; printf("┌──────────┐"); DEF_COLOR; printf("\n\t\t\t "); BOX_COLOR; printf("│ 저장하시겠습니까 ? │\n"); DEF_COLOR; printf("\t\t\t "); BOX_COLOR; printf("└──────────┘\n"); DEF_COLOR; if (menu == 1){ BEAUTI1_COLOR; printf("\n\n\t\t\t [ "); BEAUTI2_COLOR; printf("저장 후 종료"); BEAUTI1_COLOR; printf(" ] \n"); DEF_COLOR; } else puts("\n\n\t\t\t 저장 후 종료 "); if (menu == 2){ BEAUTI1_COLOR; printf("\n\t\t\t [ "); BEAUTI2_COLOR; printf("저장하지 않고 종료"); BEAUTI1_COLOR; printf(" ] \n\n\n\n\n"); DEF_COLOR; } else puts("\n\t\t\t 저장하지 않고 종료 \n\n\n\n"); bottomMessageC(); input = getch(); if (input == ARROW_BUFFER) input = getch(); switch (input) { case UP_ARROW_KEY: moveSound(); if (menu > 1) menu--; break; case DOWN_ARROW_KEY: moveSound(); if (menu < 2) menu++; break; case ENTER_KEY: inSound(); return menu; case ESC_KEY: outSound(); return 0; default: warningMessage(input - '0', 0, 0); break; } } }
int searchUser(UserInfo userInfo[], int menu) { int id, i, input, action = 1, num; char key[NAME_PHONE_BUFFER]; int overlap[OVERLAP_BUFFER]; while (1) { topMessage("검색", "Search"); switch (menu) { case 1: messageBoxA("회원 ID로 검색"); if (action){ printf("\n\n\t\t\t\t ID : "); fgets(key, NAME_PHONE_BUFFER, stdin); if (*(key + strlen(key) - 1) == '\n') *(key + strlen(key) - 1) = '\0'; else while (getchar() != '\n'); id = atoi(key); //scanf는 엔터값을 무시하기 때문에 fgets로 받고 정수로 변환하였음 num = 0; for (i = 1; i <= count; i++){ //검색 if (num + 1 >= OVERLAP_BUFFER) break; //검색 결과가 너무 많으면 버퍼 한계치에서 끊음 if (userInfo[i].userId == id) overlap[++num] = i; } } else printf("\n\n\t\t\t\t ID : %d \n", id); /* 검색 결과가 1명일 때 */ if (num == 1) return overlap[num]; /* 검색 결과가 2명 이상일 때 */ else if (num > 1) return searchManyPrint(userInfo, overlap, num); /* 검색 결과가 없을 때 */ else puts("\n\n\n\t\t\t 존재하지 않는 ID입니다 ! \n\n\n"); break; case 2: messageBoxA("이름으로 검색"); if (action){ printf("\n\n\t\t\t 이름 : "); fgets(key, NAME_PHONE_BUFFER, stdin); if (*(key + strlen(key) - 1) == '\n') *(key + strlen(key) - 1) = '\0'; else while (getchar() != '\n'); num = 0; for (i = 1; i <= count; i++){ if (num + 1 >= OVERLAP_BUFFER) break; if (strcmp(userInfo[i].userName, key) == 0) overlap[++num] = i; } } else printf("\n\n\t\t\t 이름 : %s \n", key); if (num == 1) return overlap[num]; else if (num > 1) return searchManyPrint(userInfo, overlap, num); else puts("\n\n\n\t\t\t 존재하지 않는 이름입니다 ! \n\n\n"); break; case 3: messageBoxA("연락처로 검색"); if (action){ printf("\n\n\t\t\t연락처 : "); fgets(key, ADDRESS_BUFFER, stdin); if (*(key + strlen(key) - 1) == '\n') *(key + strlen(key) - 1) = '\0'; else while (getchar() != '\n'); num = 0; for (i = 1; i <= count; i++){ if (num + 1 >= OVERLAP_BUFFER) break; if (strcmp(userInfo[i].handphone, key) == 0) overlap[++num] = i; } } else printf("\n\n\t\t\t연락처 : %s \n", key); if (num == 1) return overlap[num]; else if (num > 1) return searchManyPrint(userInfo, overlap, num); else puts("\n\n\n\t\t\t 존재하지 않는 연락처입니다 ! \n\n\n"); break; } bottomMessageA(); input = getch(); if (input == ENTER_KEY){ inSound(); action = 1; } else if (input == ESC_KEY){ outSound(); return 0; } else{ warningMessage(input - '0', 0, 0); action = 0; } } }