Created
October 24, 2017 11:31
-
-
Save rdeioris/4f4445ebe93dfaaad2fc1bcb147699c1 to your computer and use it in GitHub Desktop.
lesson002.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "aiv_math.h" | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
struct player | |
{ | |
int width; | |
int height; | |
char *name; | |
char *(*set_name)(struct player *); | |
void (*init)(struct player *); | |
}; | |
struct evil_player | |
{ | |
struct player player; | |
float evilness; | |
}; | |
static struct player super_player; | |
#define new(x) struct ##x | |
// | |
//SButton [ | |
// SText | |
//] | |
/* | |
#define > ptr++; | |
#define < ptr--; | |
#define . fp | |
*/ | |
int main(int argc, char **argv) | |
{ | |
struct player player0; | |
//player0.set_name = player_set_name; | |
player0.init(&player0); | |
player0.set_name(&player0); | |
struct player players[64]; | |
struct evil_player evil; | |
//evil.player.set_name = | |
struct player *player_parent = (struct player *)&evil; | |
memset(players, 0, sizeof(struct player) * 64); | |
char *hello = "ciao2"; | |
player0.width = 200; | |
player0.height = 300; | |
player0.name = hello; | |
char *player_name = player_set_name(&players[0]); | |
struct player *player0_ptr = &player0; | |
struct player *another_player = player0_ptr; | |
player0_ptr->width = 300; | |
player0_ptr->name = "foobar"; | |
char *copy_of_hello = malloc(6); | |
memcpy(copy_of_hello, hello, 6); | |
//hello[1] = 17; | |
int value = add(17, 22); | |
printf("ciao %u %d %s\n", -value, value + 1, copy_of_hello); | |
fprintf(stdout, "ciao %d\n", value); | |
char input[10]; | |
fgets(input, 10, stdin); | |
free(copy_of_hello); | |
return 0; | |
} | |
int add(int num0, int num1) | |
{ | |
return num0 + num1; | |
} | |
char *player_set_name(struct player *a_player) | |
{ | |
static int counter = 0; | |
counter++; | |
// malloc + memcpy | |
char *foo = strdup("ciao"); | |
char *ptr = NULL; | |
char *foo2 = malloc(10); | |
strcpy(foo2, "ciao"); | |
strcat(foo2, "hello"); | |
strcat(foo2, "hello"); | |
int len = strlen(foo2); | |
if (!strcmp(foo2, "boh")) { | |
} | |
a_player->name = malloc(6); | |
memcpy(a_player->name, "tizio", 6); | |
//memcpy(foo, a_player->name, 6); | |
return a_player->name; | |
} | |
void player_init(struct player *player) | |
{ | |
player->set_name = player_set_name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment