Yep, well as I said, this is my first go at C
Embarrassment is secondary to learning!
Not sure what I changed to make it work, but with a few little changes this code is now compiling and running for me...
# include <stdio.h>
#define STR(arg) #arg
#define BUF_SIZE 80
#define BUF_FORMAT "%80[^\n]s"
FILE *output, *input, *buffer; /* declarations*/
int main (int argc, char *argv)
if ( argc < 2 ) /* Error message if no Args entered */
printf ("\n **************** \n Not enough Arguments Supplied\n ****************\n");
printf ("\nPlease enter an Output file to append to, followed by any input files\n \n");
else /*Output file opened or created */
output = fopen(argv, "a+");
if (argc == 2) /*If only one Arg entered*/
printf ("\nA New Blank file: '%s' was created \n\nNo input files were supplied to append\n\n", argv);
else /* start append section */
i = argc -2;
j = 2;
printf ("\nThe number of files to append to: %s was %d\n\n",argv, i);
while (i > 0) /*Loop through all input files*/
/*printf ("%s\n", argv[j]);*/ /* Used for Error Checking*/
input = fopen(argv[j], "r");
if (!input) /*Check fopen worked */
printf ("FAILURE! Input File: %s Failed to Open or does not exist\n", argv[j]);
fscanf (input, BUF_FORMAT , buf);
/*printf("%s\n", buf);*/ /* Used for Error Checking */
fprintf (output, "%s\n", buf);
printf ("SUCCESS! Input File: %s was Successfully appended\n", argv[j]);
printf ("\nFiles Appended Successfully\n\n"); /*Files Appended Successfully*/
Any comments are welcome.
And a Big thank you for all the help all!
Also, how would one start implementing this same code using open, read, write, and close rather than fopen, fscanf, fprintf, and fclose?