hi, i can't seem to a.out the program for some reason. When i type in a.out, the cursor just stays there. I think it goes in a infinite loop.
I am trying to read two text files and then putting the atomic number in order. what seems to be the problem?
txt
1 Hydrogen H 1.01
1 Hydrogen H 1.01
1 Hydrogen H 1.01
50 Tin Sn 118.69
84 Polonium Po 209
88 Radium Ra 226.03
txt
1 Hydrogen H 1.01
1 Hydrogen H 1.01
1 Hydrogen H 1.01
1 Hydrogen H 1.01
1 Hydrogen H 1.01
1 Hydrogen H 1.01
11 Sodium Na 22.99
20 Calcium Ca 40.08
84 Polonium Po 209.00
#include<stdio.h>
#include<math.h>
#include<string.h>
void merge_chem(FILE * inp1, FILE* inp2, FILE* outp);
int main(void)
{
FILE *inp1, *inp2, *outp;
inp1 = fopen("chem1.txt", "r");
inp2 = fopen("chem2.txt", "r");
outp = fopen("chem.out", "w");
merge_chem(inp1,inp2,outp);
fclose(inp1);
fclose(inp2);
fclose(outp);
return 0;
}
void merge_chem(FILE * inp1, FILE* inp2, FILE* outp)
{
int atomic_num, atomic_num2;
int i = 0, j = 0, m =0, status, status2, count =1;
double weight, weight2;
char name[40], name2[40], symbol[40], symbol2[40];
status = fscanf(inp1, "%d%s%s%lf", &atomic_num, name, symbol, &weight);
status2 = fscanf(inp2, "%d%s%s%lf", &atomic_num2, name2, symbol2, &weight2);
while(status != EOF || status2 != EOF)
{
count = 1;
while(count)
{
if(atomic_num < atomic_num2)
{
fprintf(outp,"%d %s %s %.2f\n", atomic_num, name, symbol, weight);
count =0;
}
else if(atomic_num > atomic_num2)
{
fprintf(outp,"%d %s %s %.2f\n", atomic_num2, name2, symbol2, weight2);
status2 = fscanf(inp2, "%d%s%s%lf", &atomic_num2, name2, symbol2, &weight2);
}
else
{
fprintf(outp,"%d %s %s %.2f\n", atomic_num, name, symbol, weight);
status2 = fscanf(inp2, "%d%s%s%lf", &atomic_num2, name2, symbol2, &weight2);
}
}
status = fscanf(inp1, "%d%s%s%lf", &atomic_num, name, symbol, &weight);
}
}