我试图从用户那里获取输入(字符串)并将它们存储在一个数组中。但是在我运行这段代码后,程序立即崩溃了。
#include <stdio.h>
int main() {
int i;
char *word[3];
for(i=0;i<3;i++)
{
printf(" Enter a word: ");
scanf("%s", &word[i]);
}
printf("%s ", word[0]);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我想1 2 4 8 16 32 64 128 256在屏幕上打印出来.但我得到的只是0 0 0 0 0 0 0 0 0.这是我的代码:
#include<stdio.h>
#include<math.h>
void print(int n) {
if(n<=8) {
printf(" %d ",pow(2,n));
return print(n+1);
}
}
int main() {
print(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)