char* strcpy_custom(char* c1, char* c2)
{
	char* c3 = (char*) malloc(sizeof(char) *
		(strlen_custom(c1) + strlen_custom(c2) + 2));
	char* cpy = c3;
	while (*c1 != 0) {
		*c3 = *c1;
		++c3;
		++c1;
		printf("still working\n");
	}
	*c3 = *c1;
	for (int i = 0; i <= strlen_custom(c2); ++i) {
		c3[i + strlen_custom(c1) + 1] = c2[i];
	}
	return cpy;
}
Exemple #2
0
void free_command(char* params) {
    char option[20];
    bool leave = false;
    unsigned int address = 0;
    unsigned int i = 0;
    unsigned int len = 0;
    void* result = 0;

    len = strlen_custom(params);
    memset_custom(option, sizeof(option), 0);

    sscanf_custom(params, "%s", option);

    if( strcmp(option, "info") == 0 ) {
        newline();
        set_col(2);
        vprintf_custom("Usa el comando \'free\' seguido de una direccion"
                " de memoria en base hexadecimal (es decir el numero precedido"
                " por 0x o 0X), para liberar la porcion de memoria que empieza"
                " en ese lugar.");
    } else {
        for(i = 0; i < len; i++) {
            if( ishex(option[i] == false) ) {
                leave = true;
                break;
            }
        }
        //compruebo que el numero esté en hexa
        if( leave == false 
                && option[0] == '0'
                && (option[1] == 'x' || option[1] == 'X')) {
            sscanf_custom(option, "%x", &address);
            
            result = (void*)free((unsigned int*)address);
            if( result == (void*)address && (unsigned int)result > 0xF) {
                newline(); set_col(2);
                vprintf_custom("La memoria con direccion %x fue liberada.", address);
            } else {
                newline(); set_col(2);
                vprintf_custom("No existe ningun segmento de memoria alocado"
                        "en esa direccion.");
            }
        } else {
            newline(); set_col(2);
            vprintf_custom("Debes ingresar un direccion de memoria en "
                    "hexa para liberar esa porcion de memoria.");
        }
    }
}
int main()
{
	char* c = "13 characters";
	printf("%d\n", strlen_custom(c));

	char* c1 = "this";
	char* c2 = "is";
	char* c3 = "this is";
	char* c4 = "this";
	printf("%d\n", strcmp_custom(c1, c2));
	printf("%d\n", strcmp_custom(c1, c3));
	printf("%d\n", strcmp_custom(c1, c4));

	char* c5 = strcpy_custom(c1, c2);
	printf("%s\n", c5);
}