13 while(s[length] !=
'\0') {
26 char*
strcpy(
char *s1,
const char *s2)
54 while(*s==
' '){ s++; }
56 int isNeg = ( *s ==
'-');
57 if(isNeg || (*s ==
'+')){ s++; }
58 while((*s >=
'0') && (*s <=
'9' ))
60 num = (num*10) + (*s -
'0');
77 int strcmp(
const char *s1,
const char *s2)
87 for(; (s1[i]) && (s2[i]) && (s1[i]==s2[i]); i++)
104 if (*s1)
while(*++s1);
105 while( (*s1++ = *s2++) );
141 unsigned char *p = (
unsigned char *) s;
143 *p++ = (
unsigned char) c;
156 static char *tok_tmp =
NULL;
183 return (tok_tmp =
NULL);
229 int sprintf(
char *str,
int bufLength,
const char *format, ...)
232 if(!str || bufLength <= 0) {
240 int index, formatLength =
strlen(format);
241 for(index = 0; format[index] !=
'\0' && index <= formatLength; index++)
245 if(format[index] ==
'%')
247 char leftJustified=0, alwaysAppendSign=0, subSignWithSpace=0, altForm=0, padWithZeros=0;
248 int minFieldWidth=0, precision=0;
252 if(format[index]==
'\0')
256 if(!minFieldWidth && !precision)
258 switch(format[index])
260 case '-': leftJustified=1;
break;
261 case '+':
if(!leftJustified) {alwaysAppendSign=1;}
break;
262 case ' ':
if(!leftJustified && !alwaysAppendSign){subSignWithSpace=1;}
break;
263 case '#':
if(!leftJustified && !alwaysAppendSign && !subSignWithSpace) {altForm=1;}
break;
264 case '0':
if(!leftJustified && !alwaysAppendSign && !subSignWithSpace && !altForm){padWithZeros=1;}
break;
267 if(format[index] ==
'.'){ precision = -1;}
268 if(
isnum(format[index]))
272 precision =
atoi(&format[index]);
274 else if(!minFieldWidth)
276 minFieldWidth =
atoi(&format[index]);
281 if(format[index]==
'd')
283 newStrIndex +=
intToS((
int*)next_arg_in_list(&list, &format[index], 0), &str[newStrIndex], bufLength-newStrIndex);
285 else if(format[index]==
'c')
287 str[newStrIndex]= **((
char**)next_arg_in_list(&list, &format[index], 0));
290 else if(format[index]==
's')
292 char *strToCopy = *((
char**)next_arg_in_list(&list, &format[index], 0));
293 int lengthOfCopy =
strlen(strToCopy);
294 strcpy(&str[newStrIndex], strToCopy);
295 newStrIndex += lengthOfCopy;
300 str[newStrIndex] = format[index];
317 int intToS(
const int *
const i,
char *buf,
int bufLength)
336 if(bufLength<length+1)
341 cpy=(*i<0)?(*i) * -1: *i;
345 for(; length >= 0; length--)
347 buf[length] = cpy%10 +
'0';
370 case 'u':
case 'o':
case 'x':
case 'X':
371 case 'f':
case 'F':
case 'e':
case 'E':
case 'a':
case'A':
case 'g':
case 'G':
387 return ((c >=
'0') && (c <=
'9'));
void * memset(void *s, int c, size_t n)
memset Set a region of memory.
int intToS(const int *const i, char *buf, int bufLength)
intToS converts a signed integer to string
int sprintf(char *str, int bufLength, const char *format,...)
sprintf print with format to specified string buffer
char * strcat(char *s1, const char *s2)
strcat concatenates the contents of one string onto another.
int atoi(const char *s)
atoi converts and ASCII string to an integer
#define init_arg_list(argList, argBeforeEllipses)
implemented in macro because there are no templates in C
char is_conversion_specifier(char c)
is_conversion_specifier checks to see if the character is one of the standard printf formats ...
int strlen(const char *s)
strlen returns the length of a string
char * strtok(char *s1, const char *s2)
strtok Split string into tokens.
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
int isnum(const char c)
isnum inline helper function to check if a character is represents an ascii number ...
int isspace(const char *c)
isspace Determines if a character is a whitespace.
char * strcpy(char *s1, const char *s2)
strcpy copies one string to another string