Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 使用函数指向数组的指针_C_Arrays_Swap - Fatal编程技术网

C 使用函数指向数组的指针

C 使用函数指向数组的指针,c,arrays,swap,C,Arrays,Swap,这是我的密码: void bubbleSortInventory(article inventory[], int noOfArticles){ int newn; int check = 0; while(check != 0){ newn = 0; for(int i = 1; i <= noOfArticles-1;i++){ if(inventory[i-1].id>inventory[i].

这是我的密码:

void bubbleSortInventory(article inventory[], int noOfArticles){
    int newn;

    int check = 0;

    while(check != 0){
        newn = 0;
        for(int i = 1; i <= noOfArticles-1;i++){
            if(inventory[i-1].id>inventory[i].id){
                swap(&inventory[i-1].id,&inventory[i].id);
                newn = i;
            }
        }//end for-loop
        check = newn;
    }
}
现在来看问题,当我打印出数组清单时,它似乎没有被排序

有人知道我做错了什么吗

已解决,谢谢您的函数指定0来检查

…以下条件已检查!=0

…这永远都不会通过条件


while{}循环永远不会执行,因此它永远不会修改传入的数组。

格式化代码。像I这样的词要大写,不要省略撇号。如果您花更多时间正确发布问题,人们会花更多时间查看您的问题。假设您修复了检查条件的初始值…您是在尝试交换文章的ID,还是交换整个文章?您的交换函数签名不应该是Swapicle*article 1,article*article 2吗?@ludde如果有答案解决了您的问题,请务必接受绿色复选标记。谢谢,这一点上有隧道视觉,我没有注意到,现在工作得很好。
void swap(int *number1, int *number2){
    int temporaryHolder;

    temporaryHolder = *number1;
    *number1 = *number2;
    *number2 = temporaryHolder;
}
int check = 0;
while(check != 0) {
    // ...
}