I don't really have a problem as much as I want a critique. If any more experienced programmers, there are probably a lot, could look at my code and see if they can find any inconsistencies or potential problems that would be great. I've looked over it several times and walked through it with my debugger, so far it looks good.

What this program does is read a string of words from either the command line or standard input and reverses the words in that string, then prints the reversed string to either standard output or a file that the user inputs. So if you put

$prog "Hi, my name is Bebop" out.txt

the program will write to out.txt

Bebop is name my Hi,

Sorry about it not having many comments, I don't add them until the program is actually working and debugged and I'm satisfied that it's all good.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void ERROR( char *msg, char *mem );
void word_rev( char *line, FILE *str );

int main( int argc, char *argv[] )
{
	FILE *out;
	char *str_buf, *nl;
	int alloc = 0;

	/* $prog "string to rev" file */
	if( argc == 3 ) {
		out = fopen( argv[2], "w" );
		if( out == NULL )
			ERROR( "Error opening output file\n", NULL );

		str_buf = argv[1];
	}
	/* $prog "string to rev" */
	else if( argc == 2 ) {
		out = stdout;
		str_buf = argv[1];
	}
	/* $prog */
	else if( argc == 1 ) {
		out = stdout;

		str_buf = malloc( 1024 );
		if( str_buf == NULL )
			ERROR( "Error allocating memory\n", NULL );

		fprintf( stdout, "Enter a string: " );
		if( fgets( str_buf, 1024, stdin ) == NULL )
			ERROR( "Error reading from keyboard\n", str_buf );

		if( (nl = strchr( str_buf, '\n' )) != NULL )
			*nl = '\0';

		alloc = 1;
	}
	/* Bad input */
	else
		ERROR( "usage: <string> <output file>\n", NULL );

	word_rev( str_buf, out );

	if( alloc == 1 )
		free( str_buf );

	return EXIT_SUCCESS;
}

void word_rev( char *line, FILE *str )
{
	int n_words = 0;
	char *stack[1024], *sep;

	sep = strtok( line, " " );
	/* Save the words */
	while( sep != NULL && n_words < 1024 ) {
		stack[n_words++] = sep;
		sep = strtok( NULL, " " );
	}

	/* Play them back in reverse */
	while( n_words > 0 ) {
		fprintf( str, "%s", stack[--n_words] );

		if( n_words == 0 )
			fputc( '\n', str );
		else
			fputc( ' ', str );
	}
}

void ERROR( char *msg, char *mem )
{
	fprintf( stderr, msg );
	if( mem != NULL )
		free( mem );
	exit( EXIT_FAILURE );
}