Or you could simply use some form of redirection from the command line.
>Anyways, see if this helps.
Code:
#include <stdio.h>
/* Nonstandard, are you sure you need it? */
#include <conio.h>
/* Flat out wrong, void main is undefined */
void main (void)
{
/* Where do you test for a successful open? */
FILE *output = fopen("user_output.log", "a");
/* The identifier string is reserved for the implementation.
** And it should be either string[SIZE] or *string. As it is
** string is only one char when you treat it as a string.
*/
char string;
printf ("ENTER STRING");
/* gets is unsafe, it should never be used. string also
** wasn't defined as a pointer or array, so this call is
** invalid. If string were a pointer then you would need
** to allocate memory as well. */
gets (string);
/* i hasn't been declared. */
for (i=0;i <10;i++) {
/* You have one too many " in that call to printf. */
printf ("THE STRING IS "%s",string);
fprintf(output, "%s", string);
}
fclose(output);
}
This would be a bit better:
Code:
#include <stdio.h>
int main (void)
{
int i;
char str[BUFSIZ];
FILE *output = fopen ( "user_output.log", "a" );
if ( output != NULL ) {
printf ( "ENTER STRING: " );
if ( fgets ( str, sizeof str, stdin ) != NULL ) {
for ( i = 0; i < 10; i++ ) {
printf ( "THE STRING IS %s", str );
fprintf ( output, "%s", str );
}
fclose ( output );
}
}
return 0;
}
-Prelude