分配使指针没有投 [英] Assignment makes pointer without a cast

查看:84
本文介绍了分配使指针没有投的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编辑一个快速排序code,这样低,高,中间点的数组元素的而不是整数的值。

I am editing a quick sort code so that the values of low, high, and middle point to an array element instead of integers.

这是我的code:

#include <stdio.h>

#define N 10

void quicksort(int a[], int *low, int *high);
int split(int a[], int *low, int *high);

int main(void)
{
    int a[N], i;
    printf("Enter %d numbers to be sorted: ", N);
    for (i=0; i<N; i++)
        scanf("%d", &a[i]);
    quicksort(a, &a[0], &a[N-1]);

    printf("In sorted order: ");
    for (i=0; i<N; i++)
        printf("%d ", a[i]);
    printf("\n");

    return 0;
}

void quicksort(int a[], int *low, int *high)
{
    int *middle;

    if (low >= high) return;
    middle = split(a, low, high);
    quicksort(a, low, middle - 1);
    quicksort(a, middle + 1, high);
}

int split(int a[], int *low, int *high)
{
    int part_element = *low;

    for (;;) {
        while (low < high && part_element <= *high)
            high--;
        if (low >= high) break;
        *low++ = *high;

        while (low < high && *low <= part_element)
            low++;
        if (low >= high) break;
        *high-- = *low;
    }

    *high = part_element;
    return *high;
}

我收到错误消息:

I'm getting the error message:

qs.c:32:12: warning: assignment makes pointer from integer without a cast [enabled by default]
 middle = split(a, low, high);
        ^

有人可以帮助我?仍然在编程初学者。所有类型的帮助是AP preciated。

Can someone help me with this? Still a beginner at programming. All types of help are appreciated.

推荐答案

问题是这个说法。

middle = split(a, low, high);

由于是一个指针变量,而拆分是返回整数值不是一个指向整数的函数。

because middle is a pointer variable whereas split is a function which returns integer value not a pointer to an integer.

您在整型值的指针变量赋值
你不允许这样做。 :)

You are assigning integer value to a pointer variable middle . You are not allowed to do that. :)

可能这会帮助你。

这篇关于分配使指针没有投的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆