我想在不同的内存位置输入两个字符串,但在第一次输入后显示错误“分段错误(核心转储”)。我不明白这段代码有什么问题。
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
char *str;
int i;
scanf("%s",str+0);
scanf("%s",str+1);
return 0;
}
但是当我只接受一个输入时,它工作正常。
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
char *str;
int i;
scanf("%s",str+0);
return 0;
}
为什么?