调用C程序中的函数对数组进行排序时出现不合理错误

调用C程序中的函数对数组进行排序时出现不合理错误,c,gcc,assembly,mips,C,Gcc,Assembly,Mips,我编写了一个程序,从用户那里接收一系列数字(在声明SIFT之前,您没有关闭主函数,所以SIFT被声明在主函数内部,这是禁止的 在定义SIFT()之前,通过从main返回来修复它: 是的,他这样做了,main是关闭的。看起来里面嵌套了一个SIFT函数,这就是问题所在。如果他只是做了这些更改,代码末尾会有一个零散的return 0;},main不会返回任何东西(好的,但不好)。您在main函数中编写了它,请再次查看。:)你能帮我理解为什么它总是显示“数字顺序不正确…”消息吗?这是一个不同的问题,请单

我编写了一个程序,从用户那里接收一系列数字(在声明SIFT之前,您没有关闭主函数,所以SIFT被声明在主函数内部,这是禁止的

在定义
SIFT()
之前,通过从main返回来修复它:


是的,他这样做了,main是关闭的。看起来里面嵌套了一个SIFT函数,这就是问题所在。如果他只是做了这些更改,代码末尾会有一个零散的
return 0;}
,main不会返回任何东西(好的,但不好)。您在main函数中编写了它,请再次查看。:)你能帮我理解为什么它总是显示“数字顺序不正确…”消息吗?这是一个不同的问题,请单独提问。如果这是家庭作业,请贴上这样的标签,人们会更友善。此外,如果答案是所需答案,请单击其右侧的勾号进行标记。这可能是计算机架构课程的练习项目吗?如果是这样的话,也许这应该加上
家庭作业
。我在寻找“不是真正的问题/太本地化”的原因。OP出现语法错误(缺少大括号);他把它修好了;编译器停止告诉他丢失的花括号。
#include <stdio.h>
#include <string.h>

void SIFT(int x_arr[ ], int y_arr[]);

int main ()
{
    int x[20] = {0} , y[20] = {0};
    int m=0,temp=0,curr=0,i=0,j=0;

    printf("Please enter your numbers now:\n\n");

    /*enter numbers one by one. if x[i+1] value < x[i] value, err msg.
      when user want to end the series he must enter '0' which means end of string (it wont       included in x[]) */
    while ( ( temp = getchar() ) != '0' )
    {
        if (temp >= curr)
        {
            x[i] = temp;
            curr = temp;
            i++;
        }
        else
        {
            printf("The numbers are not at the right order !\n\nProgram will now terminate...\n\n");
        }
    }

    SIFT(x,y);

    for (i=0 ; y[i]=='0' ; i++) /*strlen(y) without ('0')'s includes*/
        m++;

    /*Prints  m , y's organs*/
    printf("\n\nm = %d",m);
    printf("Y = ");
    while (y[j]!='0')
    {
        printf ("%d ,",y[j]);
        j++;
    }

void SIFT(int x_arr[ ], int y_arr[])
{
    int i=0,j=0;

    while (x_arr[i] != '0')
    {
        if (x_arr[i] == x_arr[i+1]) /*if current val. equals next val. -> jump dbl at x_arr*/
        {
            y_arr[j] = x_arr[i];
            i+=2;
            j++;
        }
        else
        {
            y_arr[j]=x_arr[i];
            i++;
            j++;
        }
    }    

}

return 0;
}
gcc -g -ansi -pedantic -Wall 2.c -o 2   
2.c: In function ‘main’:
2.c:43: warning: ISO C forbids nested functions
2.c:43: warning: ISO C90 forbids mixed declarations and code
/tmp/ccyZNfkF.o: In function `main':
/home/student/Desktop/2/2.c:29: undefined reference to `SIFT'
collect2: ld returned 1 exit status
make: *** [2] Error 1
...
return 0;
}

void SIFT(int x_arr[ ], int y_arr[])
{
    int i=0,j=0;
...