Created
October 30, 2018 23:11
-
-
Save ShXck/e6226e4614fbf0ba7eaa6517bcf6e93f to your computer and use it in GitHub Desktop.
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 <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char *argv[]) { | |
printf("Los chars hola y mundo son: %d \n", strcmp("hola", "mundo")); | |
concatenate("111","666"); | |
return 0; | |
} | |
int get_len(char* c, int ctr) { | |
if(c[ctr] == '\0') return 0; | |
else return (1 + get_len(c, ++ctr)); | |
} | |
int strcmp(char* s, char* p) { | |
int s_len = get_len(s,0); | |
int p_len = get_len(p,0); | |
if(s_len > p_len) return 1; | |
else if(s_len < p_len) return -1; | |
else return 0; | |
} | |
void concatenate(char* dest, char* src) { | |
int dest_size = get_len(dest, 0); | |
int src_size = get_len(src, 0); | |
char* result = malloc(dest_size + src_size + 1); | |
memcpy(result, dest, dest_size); | |
memcpy(result + dest_size, src, src_size + 1); | |
printf(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment