fork download
  1. #include <stdio.h>
  2.  
  3. struct snake_part {
  4. int x, y;
  5. struct snake_part *next;
  6. };
  7.  
  8. struct snake {
  9. struct snake_part *head;
  10. int direction;
  11. };
  12.  
  13. struct snake create_snake(int head_x, int head_y) {
  14. struct snake_part *head = malloc(sizeof *head);
  15. head->x = head_x;
  16. head->y = head_y;
  17. head->next = NULL;
  18.  
  19. struct snake s = {head, 2};
  20. return s;
  21. }
  22.  
  23. void print_snake_info(struct snake *s) {
  24. printf("snake head coordinates: x: %d, y: %d\n", s->head->x, s->head->y);
  25. printf("snake direction: %d\n", s->direction);
  26. }
  27.  
  28. int main() {
  29. struct snake s = create_snake(10, 10);
  30.  
  31. print_snake_info(&s);
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 4540KB
stdin
Standard input is empty
stdout
snake head coordinates: x: 10, y: 10
snake direction: 2