Hi, I copied one file into another but couldn't figure out how I would number the lines and put a heading on chem.lis, which is the output.
here is the program i wrote so far
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char *argv[])
{
FILE *inp, *outp;
char ch;
argv[1] = "chem.out";
argv[2] = "chem.lis";
inp = fopen(argv[1], "r");
if(inp == NULL)
{
printf("\nCannot open file %s for for output\n", argv[2]);
exit(1);
}
outp = fopen(argv[2], "w");
if(outp == NULL)
{
printf("\nCannot open file %s for output\n", argv[2]);
exit(1);
}
for(ch = getc(inp); ch !=EOF; ch = getc(inp))
putc(ch, outp);
fclose(inp);
fclose(outp);
printf("\nCopied %s to %s\n", argv[1], argv[2]);
return 0;
}
it should look like this
************** chem.out ***************
1 1 Hydrogen H 1.01
2 11 Sodium Na 22.99
3 20 Calcium Ca 40.08
4 50 Tin Sn 118.69
5 84 Polonium Po 209.00
6 88 Radium 88 226.03
but right now it's
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
so, how should i go about doing so?