home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
APPND.ZIP
/
APPND.C
Wrap
C/C++ Source or Header
|
1991-06-25
|
3KB
|
112 lines
/***************************************************************************
Program Name : Appnd.C
Author : Rick Winkelspecht
Date Written : 24 June 1991
Compiler : Borland C++ 2.0
Language : C
Whatsitdo : This program will input 2 files and append them to
a third.
Done as a demonstration only. Feel Free to use (and
abuse- ahem, improve) this code as you see fit.
Let's call it "I don't care-ware". It is in the public
domain. If it does damage to your machine or causes it
to turn into a pumpkin, I take no responsiblity. I
don't even care if you erase my name from the Author
entry. Have fun.... Hope this can help others learn
how to copy/append files in C.
****************************************************************************/
#include <stdio.h>
#include <string.h>
void give_help(void); /* Function Prototype */
void main(int argc, char *argv[]) /* argc and argv[] look for command */
{ /* line options */
FILE *in1,*in2,*append3;
char file1[80], file2[80], file3[80];
char ch;
if(argc < 4) /* Assume no command line inputs */
{
give_help();
printf("\n\n Input File 1: "); /* Ask for File names */
gets(file1);
printf("\n\n Input File 2: ");
gets(file2);
printf("\n\n Append-to File 3: ");
gets(file3);
}
else
{
strcpy(file1,argv[1]); /* Use Command Line file names */
strcpy(file2,argv[2]);
strcpy(file3,argv[3]);
}
/* Open all files and see if they exist */
if((in1 = fopen(file1,"rb")) == NULL) /* "rb" is read-binary */
{
printf("Can't open input file %s",file1);
exit(1); /* Exit Program */
}
if((in2 = fopen(file2,"rb")) == NULL)
{
printf("Can't open input file %s",file2);
exit(1); /* Exit Program */
}
if((append3 = fopen(file3,"a+b")) == NULL) /* w+b is write-append-binary */
{
printf("Can't open input file %s",file3);
exit(1); /* Exit Program */
}
/* Read input file1 and output/append it to file3 */
while (!feof(in1))
{
ch = fgetc(in1);
if(ch != EOF) /* Strip out EOF leftovers (ascii 255) */
fputc(ch, append3);
}
/* Read input file2 and output/append it to file3 */
while (!feof(in2))
{
ch = fgetc(in2);
if(ch != EOF)
fputc(ch, append3);
}
/* All done now, close all files and quit */
fclose(in1);
fclose(in2);
fclose(append3);
}
void give_help(void)
{
printf("\n This program works two different ways.\n");
printf(" It will take input at the command line or will prompt\n");
printf(" for the input and output files.\n");
printf("\n Command Line: APPND infile1.txt infile2.txt outfile3.txt\n\n");
}