输入句子后,逐个读取单词存入数组,接着以单词为最小单位倒叙输出。
《C语言程序设计现代方法》第八章.数组 练习编程题14 个人练习。
#include <stdio.h>
#define MAX_WORDS 30
int main (void)
{
char buf[300];
char str[MAX_WORDS][15] = {0};
int i,j,t;
i = MAX_WORDS - 1;
t = 0;
puts("Please input some words :\n");
fgets(buf,300,stdin);
while (buf[t] != '\0' && buf[t] != '\n' ){
j = 0;
while (buf[t] != '\0' && buf[t] != ' '&& buf[t] != '\n'){
str[i][j] = buf[t];
j++;
t++;
}if(buf[t] == ' '){
i--;
t++;
}
}
puts("esult after the changing is :\n");
for (;i < MAX_WORDS; i++)
printf("%s ",str[i]);
return 0;
}