我正在尝试编写一个只反转字符串中单词顺序的函数。关于如何连接字符的任何提示?有我的代码。
#include <stdio.h>
#include <string.h>
#include "header.h"
/* Reverse the string character by character*/
void reverseWord (const char *str, char *wordreverse)
{
char *ptr;
int i, n = 0, length;
length = strlen( str);
strcpy( wordreverse, str);
ptr = strtok( wordreverse, " ");
while( ptr!= NULL)
{
ptr = strtok(NULL, " "); /*get next token*/
}
printf("\nTokens in reverse order are:\n");
for(i = length-1; i>=0; i--)
{
printf("%s\n", &wordreverse[i]);
ptr = strcat( &wordreverse[i], " ");
}
return 0;
}