fix: several bugs on games/tic_tac_toe.c#771
fix: several bugs on games/tic_tac_toe.c#771kvedala merged 10 commits intoTheAlgorithms:masterfrom kana800:fix_bug
Conversation
Panquesito7
left a comment
There was a problem hiding this comment.
LGTM. Thank you for your contribution! 🎉 👍
kvedala
left a comment
There was a problem hiding this comment.
a simple fix for the bug would be to simply ensure that the input number is >=0 & <=9. There is no need to make so many changes.
| * stored_pos array will store posistion of that were already allocated by the user | ||
| * calloc(9,sizeof(int)) means an array of 9 elements. | ||
| */ | ||
| int *stored_pos = NULL; |
There was a problem hiding this comment.
| int *stored_pos = NULL; | |
| static unsigned char *stored_pos = NULL; |
staticto recognize the variable as local to this file.unsigned charpointer to be same as line 30
Is this even required? isnt it serving the same purpose asgame_table?
There was a problem hiding this comment.
I can't actually remember what I have done here, but I think the purpose of stored_pos was to make sure that the values that was inserted by the user was not overwritten.
I went a bit overboard with it |
|
@Panquesito7 any idea why the autochecks are failing ? |
Good, it would be better to add your new contribution as a "v2" of the program, a new file as described in the contribution guidelines while keeping the fix to this code to its minimal. |
Kept everything to minimal, removed |
Panquesito7
left a comment
There was a problem hiding this comment.
Please fix clang-tidy warnings.
| /** | ||
| * @brief Helper function of place_x,place_y function | ||
| * | ||
| * @param None |
There was a problem hiding this comment.
No need to add this if there are no parameters.
|
@Panquesito7 please check the |
Thanks a lot ! 🙏🏽 |
@Panquesito7 |
LGTM seems to be working fine (no errors/bugs reported). |
|
My bad! It seems it has something to do with latest commit in the repository (b2def5c). |
The CI fix is present here: #796 |
|
Recheck done 👍🏽 , Everything seems to be working alright |
| { | ||
| srand( (unsigned int)time(NULL)); | ||
| int l = 0; | ||
| do |
| int main() | ||
| { srand(time(NULL)); | ||
| { | ||
| srand( (unsigned int)time(NULL)); |
| fprintf(stderr,"Invalid move, Enter number 1 - 9: "); | ||
| continue; | ||
| } | ||
| if(sscanf(input,"%d",&n1) != 1){ |
Description of Change
Issue: #729
As mentioned in the issue , The piece code listed below throws the program into an loop (from
line 247) if an invalid character is entered.else { + int n = check_placex(); - printf("Invalid move\n"); - printf("Enter new position : "); - scanf("%d", &n1); + placex(n); - placex(n1); } } else { - printf("Invalid move \n"); + int n = check_placex(); - printf("Enter new position : "); - scanf("%d", &n1); + placex(n); - placex(n1); } }Fixes / Changes
Added an array [dynamic] at
line36:+ int *stored_pos = NULL;line 47:+ stored_pos = (int*)calloc(9,sizeof(int))Assignment of the stored_pos array:
line 331,line 308&line 278example:
+ stored_pos[e] = 1;Freed the stored_pos memory
line 75+ free(stored_pos);Added a new function called
check_placesatline237toline256The
while-loopin the above above function will ask for an input until it gets a correct output.string.hlib is need)References
Checklist
Notes: