mirror of
https://github.com/cfenollosa/os-tutorial.git
synced 2024-10-27 20:34:19 +00:00
Update string.c
K&R fast implementation of reverse
This commit is contained in:
parent
7aff64740e
commit
5b5420f95a
@ -17,13 +17,16 @@ void int_to_ascii(int n, char str[]) {
|
||||
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;
|
||||
char tmp;
|
||||
int l, j;
|
||||
l = strlen(s);
|
||||
for (j = 0; j < l/2; j++){
|
||||
tmp = s[l - j - 1];
|
||||
s[l - j - 1] = s[j];
|
||||
s[j] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user