Hi,
I usually use C++, but I am working with some very old code and need to do it in C.
So i understand malloc is used
char *p;
p = malloc(200);
where 200 is the amount of bytes I need.
and yes i know I need to use free.
But I was trying to allocate an array to read a file in. and I am getting this compiler error:
test.c:13: error: invalid conversion from `void*' to `char*'
I have absolutely no idea whats wrong. Can anyone please explain?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
char *pa[1000],buffer[128];
FILE *f;
int num = 0;
f = fopen("file1_Windows.txt","r");
while (fgets(buffer,128,f) != NULL) {
pa[num] = malloc(128);
strcpy(pa[num],buffer);
num++;
}
printf("%s", pa[0]);
}