Ah okay,
Changes made.
Still the same problem persists. The input files input isn't being read
I think the problem is with the read statement...
Tidied a bit
Code:
#include <stdio.h>
#include <fcntl.h>
#define STR(arg) #arg
#define BUF_SIZE 160
#define BUF_FORMAT "%160[^\n]s"
char buf[BUF_SIZE];
FILE *output, *input, *buffer; /* declarations*/
int i,j,outfp,infp,fileread;
int main (int argc, char *argv[])
{
if ( argc < 2 ) /* Error message if no Args entered */
{
write(1, "\n **************** \n Not enough Arguments Supplied\n ****************\nPlease enter an Output file to append to, followed by any input files\n \n", 142);
return 1;
}
else /*Output file opened or created */
{
outfp = open(argv[1], O_CREAT | O_APPEND, 0777);
}
if (outfp > 0)
{
if (argc == 2) /*If only one Arg entered*/
{
write (1, "No input files appended to Output File.\n", 40);
return 0;
}
else /* start append section */
{
i = argc -2;
j = 2;
printf ("i = %d\n", i);
printf ("j = %d\n", j);
while (i > 0) /*Loop through all input files*/
{
/*printf ("%s\n", argv[j]);*/ /* Used for Error Checking*/
infp = open(argv[j], O_RDONLY);
if (infp > 0) /*Check fopen worked */
{
printf ("testing 1\n\n\n");
fileread = read (infp, buf, 160);
printf("%s\n", buf); /* Used for Error Checking */
write (outfp, buf, 160);
close(infp);
write (1,"SUCCESS! Input File: %s was Successfully appended\n", argv[j], 80);
}
else
{
write (1, "FAILURE! Input File: %s Failed to Open or does not exist\n", argv[j], 80);
}
j ++;
i --;
}
write (1, "\nFiles Appended Successfully\n\n", 80); /*Files Appended Successfully*/
close(outfp);
return 0;
}
}
else
{
/*write (1, "Output file failed to Open", 80);*/
return 1;
}
}