将一个字符数组中的字符按单词倒排,哪位大神能解决一下?
题目:输入一个句子,例如:"peak,i can play",将该句按单词倒排,标点符号都转化成空格符输出,结果:"play can i peak".最好能加上解释语句
#include <stdio.h> int main() { int i = 0, j = 1; char Str[50]; char *p[20]; gets(Str); p[0] = &Str[0]; while (Str[i] != '\0') { if(Str[i] == ' ') { Str[i] = '\0'; p[j] = &Str[i+1]; j++; } i++; } for(j = j-1; j > -1; j--) { printf("%s ", p[j]); } return 0; }