#include <stdio.h>
#include <string.h>
//reversal function
void reverseString(char* str)
{
int l, i;
char *begin_ptr, *end_ptr, ch;
l = strlen(str);
begin_ptr = str;
end_ptr = str;
//move the ptr to the final pos
for (i = 0; i < l - 1; i++)
end_ptr++;
//pointer swaping
for (i = 0; i < l / 2; i++)
{
ch = *end_ptr;
*end_ptr = *begin_ptr;
*begin_ptr = ch;
begin_ptr++;
end_ptr--;
}
}
// Driver code
- - - - - - - - - - - - - - - - -主要的 - - - - - - - - -------------------------------------------------- --------------------------------- 函数调用发送数组中第一个字符串的地址
int main()
{
char *str[ ] = {"To err is human...","But to really mess things up...","One needs to know C!!"};
for(int i=0;i<3;i++)
{
reverseString(str[i]); //funtion call
printf("Reverse of the string: %s\n", str[i]);
}
return 0;
}