GCC说"默认情况下启用]从兼容的指针类型赋值 [英] gcc saying "assignment from incompatible pointer type [enabled by default]

查看:296
本文介绍了GCC说"默认情况下启用]从兼容的指针类型赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我不断收到此错误:

Ok so I keep getting this error:

$ gcc -Wall -g translate.c support.c scanner.c -o translate
translate.c: In function ‘main’:
translate.c:22:16: warning: assignment from incompatible pointer type [enabled by default]
     dictionary = createArray(count);
            ^
support.c: In function ‘readTokens’:
support.c:66:18: warning: assignment from incompatible pointer type [enabled by default]
         a[count] = token;
              ^

和我不知道为什么。

这是我的主要功能:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "support.h"

int main(int argc, char** argv) {
    int i;
    int count;
    char** dictionary;

    if (argc != 3) {
        printf("need two arguments!\n");
        exit(-1);
    }

    count = countTokens(argv[1]);
    printf("there are %d tokens and strings\n", count);

    dictionary = createArray(count);

    readTokens(argv[1], dictionary);

    printf("The dictionary:\n");
    for (i = 0; i < count; ++i) {
        printf("%s\n", dictionary[i]);
    }
    return 0;
}

和我创建阵列功能:

char* createArray(int count) {
    char* a;
    a = malloc(sizeof(char*) * count);
    if (a == 0) {
        fprintf(stderr, "memory allocation failed\n");
        exit(1);
    }

    return a;
}

和它的标题

的char * createArray(INT);

我不知道如何得到这个走开。我试过带走并添加asteriks从一个等号更改为二,但它不工作。第二年学生CS,第一年C.任何帮助将是AP $ P $超过pciated一百万次。谢谢!

I have no idea how to get this to go away. I've tried taking away and adding asteriks and changing from one equal signs to two, but it's not working. 2nd year cs student, first year in C. Any help would be appreciated a million times over. Thanks!

推荐答案

createArray 函数声明和一个错误的工具。你需要字符数组的指针,它的类型(的char ** ),所以创建并返回这样一个数组:

Your createArray functions is declared and implement with a mistake. You need an array of char pointers, which is of type (char **), so create and return such an array:

char** createArray(int count) {
    char** a;
    a = malloc(sizeof(char*) * count);
    if (a == 0) {
        fprintf(stderr, "memory allocation failed\n");
        exit(1);
    }

    return a;
}

这篇关于GCC说&QUOT;默认情况下启用]从兼容的指针类型赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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