48 lines
No EOL
899 B
C
48 lines
No EOL
899 B
C
#include "strings.h"
|
|
#include "./platform/types.h"
|
|
|
|
void itoa(int n, char str[]) {
|
|
int i, sign;
|
|
if ((sign = n) < 0) n = -n;
|
|
i = 0;
|
|
do {
|
|
str[i++] = n % 10 + '0';
|
|
} while ((n /= 10) > 0);
|
|
|
|
if (sign < 0) str[i++] = '-';
|
|
str[i] = '\0';
|
|
|
|
strrev(str);
|
|
}
|
|
|
|
/* K&R */
|
|
void strrev(char s[]) {
|
|
int c, i, j;
|
|
for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
|
|
c = s[i];
|
|
s[i] = s[j];
|
|
s[j] = c;
|
|
}
|
|
}
|
|
|
|
/* K&R */
|
|
int strlen(char s[]) {
|
|
int i = 0;
|
|
while (s[i] != '\0') ++i;
|
|
return i;
|
|
}
|
|
|
|
char* strcpy(char* strDest, const char* strSrc) {
|
|
if ( (strDest == NULL) || (strSrc == NULL) ) {
|
|
return NULL;
|
|
}
|
|
char* strDestCopy = strDest;
|
|
while ((*strDest++=*strSrc++)!='\0');
|
|
return strDestCopy;
|
|
}
|
|
|
|
char* strcnc(char* str1, char* str2) {
|
|
char* str_dest;
|
|
strcpy(str_dest, str1);
|
|
strcpy(str_dest, str2);
|
|
} |