c语言编写程序颠倒句子enter a sentence:you can case a swallow can't you?reversal of sentence:you can't swallow a cage can you?
网友回答
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<ctype.h>
#define OK 1
#define M 5
//建单词节点
struct Node{
\x09char *data;
\x09Node *next;
};char f;
//插入函数
void Insert(Node* &S,char e[])
{\x09Node *p;
\x09p=(Node *)malloc(sizeof(Node));
\x09p->data = (char *)malloc(strlen(e)+1);
\x09p->next = NULL;
strcpy(p->data,e);
\x09p->next = S;
\x09S = p;
}void Creat(Node* &S)
{\x09int i = 0,k = 0,j,flag = 1,insert;
\x09char s[20];
\x09char a[2000] = {0};
printf("\n输入正文: ");
\x09fflush(stdin);
\x09gets(a);
printf("\n原文为: ");
\x09while(a[i] != NULL)
\x09{\x09\x09insert = 0;
\x09\x09memset(s, 0, 20);
\x09\x09j = 0;
\x09\x09// 跳过单词前面的前导字符
\x09\x09while(flag&&!isalpha(a[i])||a[i]==39)//39为'的ASCII码
\x09\x09{
\x09\x09\x09i++;
\x09\x09\x09if(a[i]==NULL)
\x09\x09\x09\x09flag = 0;
\x09\x09}
\x09\x09// 当前单词尚未结束,则一直循环
\x09\x09while(flag&&isalpha(a[i])||a[i]==39)
\x09\x09{
\x09\x09\x09insert = 1;\x09\x09\x09s[j]=tolower(a[i]);\x09\x09\x09i++;
\x09\x09\x09j++;\x09\x09}
\x09\x09//单词插入\x09\x09if(insert)\x09\x09{
\x09\x09\x09s[i] = '\0';\x09\x09\x09k++;\x09\x09\x09printf("%s\t", s);\x09\x09\x09if(k%5 == 0)\x09\x09\x09\x09printf("\n");