c - gcc saying "assignment from incompatible pointer type [enabled by default] -
ok keep getting error:
$ gcc -wall -g translate.c support.c scanner.c -o translate translate.c: in function ‘main’: translate.c:22:16: warning: assignment incompatible pointer type [enabled default] dictionary = createarray(count); ^ support.c: in function ‘readtokens’: support.c:66:18: warning: assignment incompatible pointer type [enabled default] a[count] = token; ^ and don't know why.
here's main function:
#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 2 arguments!\n"); exit(-1); } count = counttokens(argv[1]); printf("there %d tokens , strings\n", count); dictionary = createarray(count); readtokens(argv[1], dictionary); printf("the dictionary:\n"); (i = 0; < count; ++i) { printf("%s\n", dictionary[i]); } return 0; } and create arrays function:
char* createarray(int count) { char* a; = malloc(sizeof(char*) * count); if (a == 0) { fprintf(stderr, "memory allocation failed\n"); exit(1); } return a; } and header
char * createarray(int);
i have no idea how go away. i've tried taking away , adding asteriks , changing 1 equal signs two, it's not working. 2nd year cs student, first year in c. appreciated million times over. thanks!
your createarray functions declared , implement mistake. need array of char pointers, of type (char **), create , return such array:
char** createarray(int count) { char** a; = malloc(sizeof(char*) * count); if (a == 0) { fprintf(stderr, "memory allocation failed\n"); exit(1); } return a; }
Comments
Post a Comment