C数组操作题
C Array manipulation questions
所以我有几个关于读入数组的问题(对 c 很陌生)
到目前为止我有这个代码
int xZac[stCrt];
int xKonc[stCrt];
int yZac[stCrt];
int yKonc[stCrt];
for (int i=0; i < stCrt; i++) {
scanf("%d", &xZac[i]);
scanf("%d", &yZac[i]);
scanf("%d", &xKonc[i]);
scanf("%d", &yKonc[i]);
int c = xKonc[i]-xZac[i];
printf("%d", c);
//the values here shoud be xKonc[0]=49, xZac[0] = 0, it outprints 490
// but i need the actual difference between those in other inputs
//it also only returns it once even tho on the first input there should be 2 such values
//on another instance(maybe im reading them wrong?) xKonc[0]=29 and xZac[0]=0 but the output is 2907220
}
这是读入数组的正确方法吗?
然后我如何获得它的价值,我需要稍后在 for 语句中使用它,但我似乎无法正确使用它。我怎么说得到 xKonc[i]-xZac[i] 的数量。当我尝试它时,它似乎 return 指针或其他东西。所以我想知道的是如何从数组中减去实际整数,以及我是否正确读取数据或者是否存在问题
我看不出这有什么明显的错误。你能包括你的输入文件吗?我敢打赌你正在打印一个 49 和一个 0,没有换行符,让你认为你正在打印 490
所以我有几个关于读入数组的问题(对 c 很陌生) 到目前为止我有这个代码
int xZac[stCrt];
int xKonc[stCrt];
int yZac[stCrt];
int yKonc[stCrt];
for (int i=0; i < stCrt; i++) {
scanf("%d", &xZac[i]);
scanf("%d", &yZac[i]);
scanf("%d", &xKonc[i]);
scanf("%d", &yKonc[i]);
int c = xKonc[i]-xZac[i];
printf("%d", c);
//the values here shoud be xKonc[0]=49, xZac[0] = 0, it outprints 490
// but i need the actual difference between those in other inputs
//it also only returns it once even tho on the first input there should be 2 such values
//on another instance(maybe im reading them wrong?) xKonc[0]=29 and xZac[0]=0 but the output is 2907220
}
这是读入数组的正确方法吗? 然后我如何获得它的价值,我需要稍后在 for 语句中使用它,但我似乎无法正确使用它。我怎么说得到 xKonc[i]-xZac[i] 的数量。当我尝试它时,它似乎 return 指针或其他东西。所以我想知道的是如何从数组中减去实际整数,以及我是否正确读取数据或者是否存在问题
我看不出这有什么明显的错误。你能包括你的输入文件吗?我敢打赌你正在打印一个 49 和一个 0,没有换行符,让你认为你正在打印 490