- 论坛徽章:
- 0
|
帮忙看看这个答案有哪些defect 以及如何改进
#include <stdio.h>
char * stringArray[] =
{"i",
"Am",
"a",
"Boy",
"the",
"end"
};
void reverseString(char * str[],size_t size)
{
int i = 0;
char * ptrtemp ;
for(;i<size/2;i++)
{
ptrtemp = str;
str = str[size-i-1];
str[size-i-1] = ptrtemp;
}
}
int main()
{
size_t size = sizeof(stringArray)/sizeof(stringArray[0]);
printf("the string Array before reverse\n");
int i = 0;
for(i = 0; i < size; i++)
{
printf("%s\n",stringArray);
}
reverseString(stringArray,size);
printf("the string Array after reverse\n");
for(i = 0; i < size; i++)
{
printf("%s\n",stringArray);
}
printf("\n");
exit(0);
} |
|