- 论坛徽章:
- 0
|
我也试着写一个
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void inverse_by_word(char *);
int
main(void)
{
char str[] = "I am a boy\0";
printf("before inverse:\n%s\n", str);
inverse_by_word(str);
printf("after inverse:\n%s\n", str);
exit(0);
}
void
inverse_by_word(char *str)
{
char c, flag; /* flag - new word flag */
int i, len, length;
c = flag = str[0];
len = length = strlen(str);
while (c != '\0') {
if (c == ' ' || c == '\t' ||
flag == ' ' || flag == '\t')
len = strlen(str);
for (i = 0; i < len; i++)
str = str[i+1];
str = c;
flag = c;
c = str[0];
}
for ( i = 0; i < length; i++)
str = str[i+1];
str = '\0';
} |
|