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);
|
reverse(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* K&R */
|
/* K&R */
|
||||||
void reverse(char s[]){
|
void reverse(char s[]){
|
||||||
int c, i, j;
|
char tmp;
|
||||||
for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
|
int l, j;
|
||||||
c = s[i];
|
l = strlen(s);
|
||||||
s[i] = s[j];
|
for (j = 0; j < l/2; j++){
|
||||||
s[j] = c;
|
tmp = s[l - j - 1];
|
||||||
|
s[l - j - 1] = s[j];
|
||||||
|
s[j] = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user