【发布时间】:2015-08-12 12:50:29
【问题描述】:
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
char *read[100];
char *ch, *back;
int i;
ch = read;
printf("Enter a sentence and get it reversed: ");
while (getchar() != '\n') {
*ch = getchar();
ch++;
}
for (back = ch; back != read; back--) {
printf("%s",*back);
}
return 0;
}
这是我的代码。是否可以将字符串存储在数组或指针中。这种语言很古老。例如,如果用户写了 void 和 null,则输出应该是 null 和 void。我用一个指向 char 数组的指针来尝试这个,并且只想打印单词 backwords 并且它不做任何事情。我的代码有什么问题?
【问题讨论】:
-
尝试使用 scanf() 或 gets() 读取输入。不过,我不认为你的代码会做你想做的事。
-
您的问题从将
read声明为指针数组开始,然后分配read(衰减为指针,并变为指向char的指针的指针)到ch,它是指向char的指针。我相信初学者的谎言你应该能够看到指向char的指针和指向char的指针之间存在区别 -
语言太旧了?
-
em...你首先要知道
read的类型是什么。