| | |
Merging two files?
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 7
Reputation:
Solved Threads: 0
Hi, i merged two files into chem.out but i need to figure out how I would arrange them by atomic number and how i can eliminate the duplicates. Should I use structures?
here is the program i wrote so far,
chem1.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
chem2.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
this is what the output should look like
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
50 Tin Sn 118.69
84 Polonium Po 209.00
88 Radium Ra 226.03
thanks,
here is the program i wrote so far,
c Syntax (Toggle Plain Text)
#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[40], atomic_num2[40], i = 0, j = 0, m =0, status, status2; int k =0; double weight[40], weight2[40]; char name[40][40], symbol[40][40], name2[40][40], symbol2[40][40]; while(status != EOF) { status = fscanf(inp1, "%d%s%s%lf", &atomic_num[i], name[i], symbol[i], &weight[i]); i++; } i = i-1; while(status2 != EOF) { status2 = fscanf(inp2, "%d%s%s%lf", &atomic_num2[m], name2[m], symbol2[m], &weight2[m]); m++; } m = m-1; for(k = 0; k < m; k++) fprintf(outp,"%d %s %s %.2f\n", atomic_num2[k], name2[k], symbol2[k], weight2[k]); for(j = 0; j < i; j++) fprintf(outp,"%d %s %s %.2f\n", atomic_num[j], name[j], symbol[j], weight[j]); }
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
chem2.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
this is what the output should look like
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
50 Tin Sn 118.69
84 Polonium Po 209.00
88 Radium Ra 226.03
thanks,
Last edited by Ancient Dragon; Dec 5th, 2007 at 10:00 pm. Reason: add code tags
![]() |
Similar Threads
- Partition Magic nightmare (Windows NT / 2000 / XP)
- Windows 2000 - Windows Explorer folder view is gone (Windows NT / 2000 / XP)
- merging tiff files and print to pdf format (Visual Basic 4 / 5 / 6)
- Looping and data merging (Python)
- Toolbars gone wild after Freshbar removal (Viruses, Spyware and other Nasties)
- got rid of about:blank and freshbar but am still having popup problems (Viruses, Spyware and other Nasties)
- Working with array of files (C++)
- Crunchie, can you help me? (Viruses, Spyware and other Nasties)
Other Threads in the C Forum
- Previous Thread: help me, how to correct the error for this C program
- Next Thread: hot to get a return value from a function executed by a pthread
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






