Okay..here goes...lemme explain my thoughts first (please feel free to correct me, just not too harsh, a'ight :-). I know I need an output, the length (or an int) and ptr to the source. so the output is line, the length is LINE_LEN and the ptr is file...code is below:
Code:
#include <stdio.h>
#include <string.h>
#define LINE_LEN 80
#define NAME_LEN 40
int main ( int argc, char *argv[])
{
char ch;
char *w;
char *status;
char buffer[20];
int i = 0;
if ( argc != 2 ) // argc should be 2 for correct execution
{
// We print argv[0] assuming it is the program name
printf( "usage: %s <filename> (please type a filename)", argv[0] );
}
else
{
FILE *file = fopen( argv[1], "r" ); // Filename to open
w = argv[1]; //First file name to create
//Create the new file with *.blah extension
sprintf(buffer, "%s.blah", argv[1]);
FILE *newfile = fopen(buffer, "w");
//Add the new Heading to the file
fprintf(newfile,"********************%s.blah******************\n\n\n\n", w);
/* fopen returns NULL, on failure */
if ( file == NULL )
{
printf( "Could not open file\n" );
}
else
{
/* read one character at a time from file, stopping at EOF, which
indicates the end of the file. */
{
for (ch = getc(file); ch != EOF; ch = getc(file))
putc(ch, newfile);
}
char line[LINE_LEN], linein[NAME_LEN],lineout[NAME_LEN];
for (status = fgets(line, LINE_LEN, file);
status != 0;
status = fgets(line, LINE_LEN, file))
{
if (line[strlen(line) -1] == '\n') line[strlen(line) - 1] = '\0';
fprintf(newfile, "%3>> %s\n", ++i, line);
}
}
fclose( file );
fclose( newfile );
}
}