Apart from the horror of using gets
, you land straight into undefined behaviour as the str
variable is not initialized and thus points to a random location.
consider this:
char tmp[256];
for (int j = 0; j < 6; j++) {
fgets(tmp, sizeof(tmp), stdin);
tmp_ans[j] = strdup(tmp);
}
Note I left out error checking. You should add that.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…