D
Defected
Thanks all for help,
I have tried this code but it's don't work.
--------------------------------------------------------------------
Structure
typedef struct{
int atomic_number;
char name[MAX];
char symbol[MAX];
double weight;
}chemical_t;
-----------------------------------------------------------------------
void merge(FILE *element_1, FILE *element_2, FILE *element){
chemical_t chemical;
chemical_t chemical_1;
chemical_t chemical_2;
element_1 = fopen("text.txt", "r");
element_2 = fopen("text1.txt", "r");
element = fopen("text.bin", "wb");
fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_number,
chemical_1.name,
chemical_1.symbol,
&chemical_1.weight);
fscanf(element_2,"%d%s%s%lf",&chemical_2.atomic_number,,
chemical_2.name,
chemical_2.symbol,
&chemical_2.weight);
while(!feof(element_1)){
if(chemical_1.atomic_number < chemical_2.atomic_number){
fwrite(&chemical_1, sizeof(chimico_t), 1, element);
fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_number,
chemical_1.name,
chemical_1.symbol,
&chemical_1.weight);
}
else{
while(!feof(element_2)){
fwrite(&chemical_2, sizeof(chimico_t), 1, element);
fscanf(element_2,"%d%s%s%lf",&chemical_2.atomic_number,,
chemical_2.name,
chemical_2.symbol,
&chemical_2.weight);
}
}
}
fclose(element_1);
fclose(element_2);
fclose(element);
}
---------------------------------------------------------------------------------------------
My program must make this:
I have need to write a void function that will merge the contents of two
text file containing chemical elements sorted by atomic number and will
produce a sorted file of binary records. The funcion's parameters will
be three file pointers.
Each text file line contain for example:
11 Sodium Na 22.99
20 Calcium Ca 40.08
The function can assume that one file does not have two copies of the
same element and that the binary output files should have this same
property.
When one of the input files is exhausted, do not forget to copy the
remaining elements of the other input file to the result file.
Tanks and best regards
Sorry for my English
I have tried this code but it's don't work.
--------------------------------------------------------------------
Structure
typedef struct{
int atomic_number;
char name[MAX];
char symbol[MAX];
double weight;
}chemical_t;
-----------------------------------------------------------------------
void merge(FILE *element_1, FILE *element_2, FILE *element){
chemical_t chemical;
chemical_t chemical_1;
chemical_t chemical_2;
element_1 = fopen("text.txt", "r");
element_2 = fopen("text1.txt", "r");
element = fopen("text.bin", "wb");
fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_number,
chemical_1.name,
chemical_1.symbol,
&chemical_1.weight);
fscanf(element_2,"%d%s%s%lf",&chemical_2.atomic_number,,
chemical_2.name,
chemical_2.symbol,
&chemical_2.weight);
while(!feof(element_1)){
if(chemical_1.atomic_number < chemical_2.atomic_number){
fwrite(&chemical_1, sizeof(chimico_t), 1, element);
fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_number,
chemical_1.name,
chemical_1.symbol,
&chemical_1.weight);
}
else{
while(!feof(element_2)){
fwrite(&chemical_2, sizeof(chimico_t), 1, element);
fscanf(element_2,"%d%s%s%lf",&chemical_2.atomic_number,,
chemical_2.name,
chemical_2.symbol,
&chemical_2.weight);
}
}
}
fclose(element_1);
fclose(element_2);
fclose(element);
}
---------------------------------------------------------------------------------------------
My program must make this:
I have need to write a void function that will merge the contents of two
text file containing chemical elements sorted by atomic number and will
produce a sorted file of binary records. The funcion's parameters will
be three file pointers.
Each text file line contain for example:
11 Sodium Na 22.99
20 Calcium Ca 40.08
The function can assume that one file does not have two copies of the
same element and that the binary output files should have this same
property.
When one of the input files is exhausted, do not forget to copy the
remaining elements of the other input file to the result file.
Tanks and best regards
Sorry for my English