File processing typedef struct hw5_struct { char f_name[12]; char l_name[12]; in
ID: 3602682 • Letter: F
Question
File processing
typedef struct hw5_struct
{
char f_name[12];
char l_name[12];
int age;
float height;
} HW5_struct;
File struc_data.dat is located in directory /home/f/fl/floodw/HW5/HW5_data
Your task will be to use the supplied structure, determine how large the file is, dynamically allocate memory for the entire file. Read the file structure by structure into this memory. Then you will update the structure by adding a birthday and a street address.
After this is done you are to write this data into a temporary file within your directory structure called my_temp.tmp
Within the my_temp.tmp file you will update the age and height of each record in this order: 3,5,7,1,9,2,8,4,6,10. Each person has aged and will either grow up or grow down. The time difference will be 15 years.
Please research this and be accurate:
What should be seen: A printout of each record of the current file being used every time you perform a task. So what that means is: You read the file. You created a new file, you updated a single record. Each of these events warrants the entire file being printed.
The last task is: create a different file called sort.dat. Using the first name in each record you will place the entire record into the new file. Use the ASCI chart. Low too high. Then print this file out.
When all is said you need to clean up and delete your temporary file.
Hint: SEEK.
Explanation / Answer
#include //Always use meaningful names for types typedef unsigned char boolean; #define True 't' #define FALSE (!True) //this is a really neat trick for swapping values efficiently void swap(long* a,long *b) { *a=*a^*b;*b=*b^*a;*a=*a^*b; } //Here's a readability improvement #define until(condition) while(!(condition)) int main(int n, char*args[]){ double *d; int i; char input[5]; //should be long enough for most doubles. boolean sorted = FALSE; //In C, you need to specify the array size beforehand, so ask printf("Please enter the length of the array "); gets(input); //scan the input string and convert to a value sscanf(input,"%s",&input[0]); n=(long)atol(input); //allocate space, make sure you get the order of arguments right. d = calloc(sizeof(double),n); //Get and sort the array until (sorted) { for (i=0;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.