Lesson 20 step 1, the timer

This commit is contained in:
Carlos
2015-03-19 20:07:50 +01:00
parent 1a98cab56b
commit 7797630a24
4 changed files with 28 additions and 9 deletions

View File

@@ -26,5 +26,22 @@ void int_to_ascii(int n, char str[]) {
if (sign < 0) str[i++] = '-';
str[i] = '\0';
/* TODO: implement "reverse" */
reverse(str);
}
/* K&R */
void reverse(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;
}

View File

@@ -6,5 +6,7 @@
void memory_copy(char *source, char *dest, int nbytes);
void memory_set(u8 *dest, u8 val, u32 len);
void int_to_ascii(int n, char str[]);
void reverse(char s[]);
int strlen(char s[]);
#endif