#include<stdio.h>
#include<string.h>
int main()
{
char str[81];
char str2[80][81];
char *p;
int i,count=0;
gets(str);
p=strtok(str," ");
while(p!=NULL)
{
strcpy(str2[count],p);
p=strtok(NULL,"\n");
count++;
}
for(i=count-1;i>0;i--)
printf("%s",str2[i]);
printf("%s",str2[0]);
return 0;
}
#include<string.h>
int main()
{
char str[81];
char str2[80][81];
char *p;
int i,count=0;
gets(str);
p=strtok(str," ");
while(p!=NULL)
{
strcpy(str2[count],p);
p=strtok(NULL,"\n");
count++;
}
for(i=count-1;i>0;i--)
printf("%s",str2[i]);
printf("%s",str2[0]);
return 0;
}
本文介绍了一个简单的C语言程序,该程序使用标准输入输出库和字符串处理函数,实现了从用户接收一行字符串并将其按单词逆序输出的功能。文章通过示例代码详细解释了如何利用gets()函数读取字符串、strtok()函数进行字符串分割以及如何实现逆序输出。
181

被折叠的 条评论
为什么被折叠?



