Reputation: 93
its time over but anyway i want finish this problem. I want read binary file to buffer and later i want copy this buffer to array. I'm doing like that;
int i=0;
char *buffer;
buffer=(char *)malloc(filelen+1); //filelen is length of binary file
while()
{
fread(buffer,100,1,filepointer); //filepointer is input binary file pointer,i wanna read 100 byte
strcpy(tup[i],buffer); //tup[] is char array.i want copy buffer to in this array
i++;
}
i got error at strcpy line you can not copy pointer to integer something like that.
thanx.
Upvotes: 0
Views: 4322
Reputation: 3912
It must be:
strcpy(tup,buffer);
if tup is char* tup
.
Also you can use buffer[filelen]=0;
after you've used malloc()
to allocate the memory for buffer
, this will take care of the '\0'
termination.
Upvotes: 1
Reputation: 28892
I think you want to write:
strcpy(&tup[i],buffer);
There are however a number of other issues.
memcpy
instead (with a known calculated length)tup
?Upvotes: 3