Hello. I need help with a thing.
I have a file (sound file) I will send via controller area network and therefore can only send data about 8 byte or 8 vector as data [8]. This is sent away with the command sendfile ()
And I need help how I will do this code
Stages 1:
I will firstly read in the file to one vector as examples file []. How do I do this? Is there some completed code for this?
Stages 2:
Read in the first 8 vector to data [], then send this.
Stages 3:
Read vector 9 to vector 17 to dates [], then send this.
This happens until the entire file has been sent.
pleas help me to give a basis on how I will intend and to type the code.
///
I must apology for my poor English
Anders

by vector do you mean a character array ? Such as char data[255]; Use the FILE and associated functions located in stdio.h to read and write files. Here is a tutorial.

Exact. Thanks for the advice.The file I will read in is sound.wav or sound.mp3. Can I read in that file to char data [255]. Or must I do it to binary first
//
Anders

since its binary data it will be better to read it into unsigned char array. There is one way to do it.

unsigned char* buf = 0;
size_t filesize = 0;
FILE* fp = fopen("sound.mp3","rb");
// get the size of the file and allocate input buffer space
fseek(fp,0,SEEK_END); 
filesize = ftell(fp);
// go back to beginning of file
fseek(fp,0,SEEK_SET);
// allocate input buffer
buf = malloc(filesize);
// read into buffer
fread(buf,1,filesize,fp);
fclose(fp);
This question has already been answered. Start a new discussion instead.