关于c语言指针数组的题目输出烫tangtang(中文字符)
今天在写c primer plus第十一章11.13的时候遇到了一道习题 ,一直没有解决。(环境是 VS2022)
__13.编写一个程序,反序显示命令行参数的单词。例如,命令行参数是
see you later,该程序应打印later you see。
然后我写的代码如下
(这里主要是想要用输入输出来实现,没有用命令行参数orz)
#define SIZE_13_1 50
#define SIZE_13_2 10
int get_words(char(*string)[SIZE_13_2], char** str, int n) {
int i = 0,j = 0 ;
bool inword = false;
char ch;
printf("Please enter no more than 49 words and each word is no more than 9 characters:\n");
while ((ch = getchar()) != EOF && i < n) {
if (!isspace(ch) && !inword) {
*(*(string + i) + j) = ch;
j++;
inword = true;
}
else if (!isspace(ch) && inword) {
*(*(string + i) + j) = ch;
j++;
}
else if (isspace(ch) && inword) {
*(*(string + i) + j) = '\0';
str[i] = string[i];
i++;
inword = false;
}
}
str[i] = '\0';
return i -1;
}
//输出words时候 在前面出现 烫tangtang
int ex1113(void) {
char string[SIZE_13_1][SIZE_13_2];
char* str[SIZE_13_1];
int n;
int j;
n = get_words(string,str,SIZE_13_1);
for(j=n;j>=0;j--)
printf(str[j]);
putchar('\n');
}
int main(void) {
ex1113();
return 0;
}
运行结果及报错内容
在每一个单词的前面又出现了烫tangtang,而且输出第一个单词的第一个字母也会被汉字代替
在输入很多个单词的时候,还会有一些单词消失
请教各位orz 应该怎么改一下可以实现单词的倒序输出啊 T T