When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
45 messages ยท Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
void initialise_map(enum land map[SIZE][SIZE]) {
for (int row = 0; row < SIZE; ++row) {
for (int col = 0; col < SIZE; ++col) {
map[row][col] = NOT_VISITED;
}
}
}
void print_map(enum land map[SIZE][SIZE]) {
for (int row = 0; row < SIZE; ++row) {
for (int col = 0; col < SIZE; ++col) {
if (map[row][col] == NOT_VISITED) {
printf(". ");
} else if (map[row][col] == VISITED) {
printf("- ");
} else if (map[row][col] == SNAKE) {
printf("S ");
} else if (map[row][col] == APPLE) {
printf("A ");
}
}
printf("\n");
}
}```
if you " combine" that code into one file essentially then thats my program
max char limit is fucking annoying
anyways
hopefully what its inteded to do should be somewhat understandabkle
but im getting the strangest behavouir and for the life of me i cannot figure out why
Please enter apple location: 2 3
Please enter snake location: 4 5
. . . . . . . .
. . . . . . . .
. . . A . . . .
. . . . . . . .
. . . . . S . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
r
. . . . . . . .
. . . . . . . .
. . . A . . . .
. . . . . . . .
. . . . . S . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
d
. . . . . . . .
. . . . . . . .
. . . A . . . .
. . . . . . . .
. . . . . - S .
. . . . . . . .
. . . . . . . .
. . . . . . . .
d
. . . . . . . .
. . . . . . . .
. . . A . . . .
. . . . . . . .
. . . . . - - .
. . . . . . S .
. . . . . . . .
. . . . . . . .
l
. . . . . . . .
. . . . . . . .
. . . A . . . .
. . . . . . . .
. . . . . - - .
. . . . . . - .
. . . . . . S .
. . . . . . . .
l
. . . . . . . .
. . . . . . . .
. . . A . . . .
. . . . . . . .
. . . . . - - .
. . . . . . - .
. . . . . S - .
. . . . . . . .
l
. . . . . . . .
. . . . . . . .
. . . A . . . .
. . . . . . . .
. . . . . - - .
. . . . . . - .
. . . . S - - .
. . . . . . . .
l
. . . . . . . .
. . . . . . . .
. . . A . . . .
. . . . . . . .
. . . . . - - .
. . . . . . - .
. . . S - - - .
. . . . . . . .
d
. . . . . . . .
. . . . . . . .
. . . A . . . .
. . . . . . . .
. . . . . - - .
. . . . . . - .
. . S - - - - .
. . . . . . . .
u
. . . . . . . .
. . . . . . . .
. . . A . . . .
. . . . . . . .
. . . . . - - .
. . . . . . - .
. . - - - - - .
. . S . . . . . ```
the snake only moves
upon inputting a SECOND character
regardless of what the character
but i have no fuycking idea why
this is sooooooooooooooooooo fucking strange lmao
Don't do scanf("%c ") but rather do scanf(" %c")
whats the difference?
The first expects a character and a whitespace (I think), the second ignores any whitespace (including newlines which is where I think the error stems from).
I do have to admit that I don't really know the difference for sure but yeah, you shouldn't ever use scanf in the first place: https://sekrit.de/webdocs/c/beginners-guide-away-from-scanf.html
Yes
i wasnt really sure how to
for example like
lets say the grid was bigger like 12x12
and i inputted 12 12
Yeah?
i would get smth like c {'1', '2', ' ', '1', '2', '\n', '\0'} right @dire sand
Yes
then how would i like
get those numbers "added" together im not really sure how to word it
You can remove any possibly trailing newline from a string s by doing:
s[strcspn(s, "\n")] = 0;
like the digits connected into an integer
You can either do that manually but I personally would just use strtol
if i were to do it manually?
!man strtol
strtol, strtoll, strtoq - convert a string to a long integer
#include <stdlib.h>
long strtol(const char *restrict nptr,
char **restrict endptr, int base);
long long strtoll(const char *restrict nptr,
char **restrict endptr, int base);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
strtoll():
_ISOC99_SOURCE
|| /* Glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
as my uni course has not really
explained anything ๐
like if i were to do it with a while loop or smth
the only string function we did was strcopy
Does your code work with scanf(" %c") btw?
it does ๐
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity