C程序输出在不同的机器上不同

C程序输出在不同的机器上不同,c,arrays,C,Arrays,我有以下程序- #include <stdio.h> int main() { int counter = 0; int responses[28]; printf("Enter student section values: \n"); while(counter != 27) { scanf("%d", &responses[counter]); counter++; } int i =

我有以下程序-

#include <stdio.h>

int main() {
    int counter = 0;

    int responses[28];
    printf("Enter student section values: \n");
    while(counter != 27) {
        scanf("%d", &responses[counter]);
        counter++;
    }

    int i = 0;
    int arrayBlank[100];
    int temp = 0;
    int past = 0;
    int present = 0;
    int future = 0;
    int flag = 0;
    for(i = 0; i < counter; i++) {
        if((i - 1) < 0 || (i + 1 >= counter)) {
            ;
        }
        else {
            past = responses[i - 1];
            present = responses[i];
            future = responses[i + 1];
            if(present == past || present == future) {
                temp = present;
                flag=1;
                arrayBlank[temp]++;
            } else {
                arrayBlank[i] = 0;
            }
        }
    }

    if(flag == 0) {
        printf("\nThe order input does not assign any adjacent students from the same team\n");
        return 0;
    } else {
        int chut[28];
        int index = 0;
        for(i = 0; i < 27; i++) {
            index = responses[i];
            chut[index]++;
        }

        for(i = 0; i < 27; i++) {
            if(chut[i] <= 0 || chut[i] > 26) {
                chut[i] = 0;
            }
        }
        printf("\nThe order input currently assigns adjacent students from the same team.\n");
        printf("\nTeam Students\n");
        for(i = 0; i < 27; i++) {
            if(chut[i] != 0) {
                printf("%d %d\n", i, chut[i]);
            }
        }
        //1 2 3 3 4 5 6 7 8 9 1 2 3 4 5 5 7 8 9 1 2 3 4 5 6 7 8 8

    }
    return 0;
}
问题:我无法找出不同机器上输出不同的原因,以及如何解决这一问题。例如,在使用XCode运行程序的Macbook上,输出是正确的,但在使用gcc编译器(Big-Endian机器)的Linux机器上运行时,输出是不同的。我不确定Endianess是否与输出不同有关

在一台小小的Endian Linux机器上-

在Big-Endian Linux机器上-

在联机编译器()上-


据我所知,主要问题是您尚未初始化
arrayBlank
,并且正在使用它:

arrayBlank[temp]++;
这当然是未定义行为的原因。我将使用

int arrayBlank[100] = {0};
第二个问题是读取数据的循环计数器不正确。而不是:

while(counter != 27) {
    scanf("%d", &responses[counter]);
使用:


当您使用
计数器时!=27
要停止,可使用索引
27
访问的
响应的最后一个元素永远不会从文件中读取。

您忘了初始化
arrayBlank
,因此它以垃圾开始。这只是许多问题中的一个。谢谢你指出这一点。我已经解决了这个问题,尽管这并没有像你说的那样解决问题。big-endian x64机器存在吗?
chut
也没有初始化。谢谢!问题是chut也没有初始化。感谢您的回复。我试过了,但似乎没有帮助。问题是chut以及arrayBlank没有初始化。我将它们初始化为{0},解决了这个问题。@NatureDevil,很高兴您在没有外部帮助的情况下解决了另一个问题:)
while(counter != 27) {
    scanf("%d", &responses[counter]);
while(counter != 28) {
    scanf("%d", &responses[counter]);