Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: apply some fixes #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions 2048.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void drawBoard(uint8_t board[SIZE][SIZE], uint8_t scheme, uint32_t score)
{
uint8_t x, y, fg, bg;
printf("\033[H"); // move cursor to 0,0
printf("2048.c %17d pts\n\n", score);
printf("2048.c %17u pts\n\n", score);
for (y = 0; y < SIZE; y++)
{
for (x = 0; x < SIZE; x++)
Expand Down Expand Up @@ -164,7 +164,7 @@ void rotateBoard(uint8_t board[SIZE][SIZE])
uint8_t tmp;
for (i = 0; i < n / 2; i++)
{
for (j = i; j < n - i - 1; j++)
for (j = i; j < (uint8_t)(n - i - 1); j++)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inline construct may be confusing for beginning programmers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What alternatives do you suggest? Should I assign the expression to a variable?

{
tmp = board[i][j];
board[i][j] = board[j][n - i - 1];
Expand Down Expand Up @@ -404,7 +404,7 @@ int test()
{
printf("%d ", array[i]);
}
printf("(%d points) expected ", score);
printf("(%u points) expected ", score);
for (i = 0; i < SIZE; i++)
{
printf("%d ", in[i]);
Expand Down Expand Up @@ -439,7 +439,7 @@ int main(int argc, char *argv[])
uint8_t board[SIZE][SIZE];
uint8_t scheme = 0;
uint32_t score = 0;
char c;
int c;
bool success;

if (argc == 2 && strcmp(argv[1], "test") == 0)
Expand Down Expand Up @@ -467,7 +467,7 @@ int main(int argc, char *argv[])
while (true)
{
c = getchar();
if (c == -1)
if (c == EOF)
{
puts("\nError! Cannot read keyboard input!");
break;
Expand Down