I'm trying to copy a file. I'm using a borrowed code snippet, and there's a line of it which errors which confuses me.
int fileread = open("original.txt", O_RDONLY);
void *buffer;
buffer = malloc(sizeof(void) * size); /*This line gives "Incomplete type not allowed."*/
int nread = read(fileread,buffer,size);
int filewrite = open("original.txt.backup",O_CREAT | O_RDWR, 0644);
write(filewrite,buffer,size);
close(filewrite);
close(fileread);
What should I be using instead? I was thinking char*, but I want to make sure I'm understanding the process going on here.
sizeof() returns the size of your type. Honestly I think you should just change it to
char *buffer;
buffer = malloc(sizeof(char) * size);
Sizeof(void) makes zero sense