cracking the coding interview No1.2

来源:互联网 发布:网络的拓扑结构是指 编辑:程序博客网 时间:2024/06/05 10:13


1.2Implement a function vod reverse(char *str)in C or C++which reverses a null-terminated string.


void reverse(char *str){if (str == NULL)return;char *str1 = str;int length = 0;while (*str1!='\0'){length++;}for (int i = 0;i < length/2; i++){int temp = *(str + i);*(str + i) = *(str + length - i - 1);*(str + length - i - 1) = temp;}}

0 0