mirror of
https://github.com/TheAlgorithms/C.git
synced 2026-02-04 05:44:35 +00:00
[PR #778] [CLOSED] Update tic_tac_toe.c #1293
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/TheAlgorithms/C/pull/778
Author: @driti924
Created: 12/16/2020
Status: ❌ Closed
Base:
master← Head:driti924_Update_tic_tac_toe📝 Commits (2)
f72f7c9Update tic_tac_toe.c9cfbdb9Update tic_tac_toe.c📊 Changes
1 file changed (+46 additions, -14 deletions)
View changed files
📝
games/tic_tac_toe.c(+46 -14)📄 Description
Successful exceptional handling
Description of Change
Issue: #729
Fixes / Changes
#line no 16
[+] #include <string.h>
First, I changed type of 'n' from int to char, so that if player enters any character other than a number it still gets consumed and does not remain in input buffer. As this input buffer effects the scanning of next number(i.e 'l' here) and doesn't scan player's choice to play again.
#line no 41
[-] int n = 0;
[+] char n = '0';
Second, to avoid infinite loop on getting any character on line no.247 , I have added a new function 'TakeInput'. Thus a player can enter any character/s or number(not in range of 1-9) without entering infinite loop. This time a message will prompt them to give valid input.
Also note, my code is always using TakeInput function to input players choice to avoid the same problem of unused input buffer.
#line no 21
[+] static int TakeInput(); // used to take input from player and handle exceptions accordingly
#line no 85
[+] int TakeInput(){
}
Other changer are made accordingly. Like
#line no 54
[-] scanf("%d", &n);
[+] scanf(" %c", &n);
#line no 59
[-] case 1:
[+] case '1':
#line no 62
[-] case 2:
[+] case '2':
For better visibility
#line no 66
[-] printf("THANK YOU and EXIT!");
[+] printf("THANK YOU and EXIT!\n");
lines 105 and 176
[-] scanf("%d",&m)
[+] m=TakeInput()
#line no 182
[-] scanf("%d", &e1);
[+] e1=TakeInput();
#line no 242 and 252
[-] scanf("%d", &n1);
[+] n1=TakeInput();
For better visibility
line no 272
[-] printf("\n Computer placed at %d position\n", e + 1);
[+] printf("\nComputer placed at %d position\n", e + 1);
#line no 301 and 311
[-] scanf("%d", &n1);
[+] n1=TakeInput();
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.