D
Defected
Hi All,
I have problem whit this program, because the output file print copies
but only at the end of file, and the file does not have two copies of
the same element.
Example of elements in the two file:
11 Sodium Na 22.99
20 Calcium Ca 40.08
------------------------------------------------------------------------
Structure
typedef struct{
int atomic_number;
char name[MAX];
char symbol[MAX];
double weight;
}chemical_t;
------------------------------------------------------------------------
while(!feof(element_1)){
fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_number,
chemical_1.name,
chemical_1.symbol,
&chemical_1.weight);
while(!feof(element_2)){
fscanf(element_2,"%d%s%s%lf",&chemical_2.atomic_number,,
chemical_2.name,
chemical_2.symbol,
&chemical_2.weight);
for(i = 0; i < el_1; i++){
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{
for(j = 0; j < el_2; j++){
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);
}//end for
}//end else
}//end for
}//end while
}//end while
Thanks
I have problem whit this program, because the output file print copies
but only at the end of file, and the file does not have two copies of
the same element.
Example of elements in the two file:
11 Sodium Na 22.99
20 Calcium Ca 40.08
------------------------------------------------------------------------
Structure
typedef struct{
int atomic_number;
char name[MAX];
char symbol[MAX];
double weight;
}chemical_t;
------------------------------------------------------------------------
while(!feof(element_1)){
fscanf(element_1,"%d%s%s%lf",&chemical_1.atomic_number,
chemical_1.name,
chemical_1.symbol,
&chemical_1.weight);
while(!feof(element_2)){
fscanf(element_2,"%d%s%s%lf",&chemical_2.atomic_number,,
chemical_2.name,
chemical_2.symbol,
&chemical_2.weight);
for(i = 0; i < el_1; i++){
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{
for(j = 0; j < el_2; j++){
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);
}//end for
}//end else
}//end for
}//end while
}//end while
Thanks