My task is to convert the data file from one end to the other (from the big end to the small one and vice versa) using C. I look online for about 3 hours for other examples and read my tutorial, however I am so fixated on how to start this function . So far, my order of events is correct (from 1 to 4), but inside my function "convert_and_save" I have to create a char array using → char buffer [4]; Can someone please help me? even if you just let me know what to see, I would really appreciate it.
I need to write a function:
void convert_and_save (structure record element, FILE * output_handle, int number);
inside this function, follow these steps:
(1) Convert an integer to an array of characters using:
int integer_to_characters(int number, char * buffer)
{
memcpy(buffer, &number, 4);
}
(2) Reorder the character order in this array.
(3) Convert the array of characters back to an integer using:
int characters_to_integer(char * buffer)
{
int result;
memcpy(&result, buffer, 4);
return result;
}
(4) write the converted record to the output file using:
void save_record(FILE * file_handle, struct record a)
{
char output_buffer[size_of_record];
integer_to_characters(a.age, &(output_buffer[0]));
memcpy(&(output_buffer[4]), a.name, 12);
integer_to_characters(a.department, &(output_buffer[16]));
fwrite(output_buffer, sizeof(char), size_of_record, file_handle);
}