Last active
December 14, 2015 08:39
-
-
Save coldcue/5059497 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "nem_oo.h" | |
void strcpy(char *dest, const char *source) | |
{ | |
while((*dest++=*source++)!='\0'); | |
} | |
unsigned int strlen(const char *str) | |
{ | |
unsigned int len=0; | |
while(*(str+len++)!='\0'); | |
return len-1; | |
} | |
int sajat::atoi(const char *p, int base) | |
{ | |
const char *it; | |
int ret = 0; | |
// Iterate through the numbers | |
for(it=p; *it!='\0' && *it!=' '; it++) | |
{ | |
char val = *it - '0'; | |
if(val >= base) throw "Wrong number system!"; | |
ret = ret*base + val; | |
} | |
return ret; | |
} | |
char *sajat::strcat(const char *p1, const char *p2) { | |
unsigned int len1 = strlen(p1), len2 = strlen(p2); | |
char *ret = new char[len1+len2+1]; | |
strcpy(ret,p1); | |
strcpy(ret+len1,p2); | |
return ret; | |
} | |
void sajat::swap(int& r1, int& r2) { | |
int temp = r1; | |
r1 = r2; | |
r2 = temp; | |
} | |
char *sajat::unique(char *first, char *last) { | |
char *lu = first, *it = first; | |
do { | |
it++; | |
if(*it==*lu) continue; | |
*++lu = *it; | |
} while(it!=last); | |
return lu+1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment