Can anyone help? New programmer trying to write Program that prompts user to enter name of file to display on screen.
User is given to option to display another file until the user ends program. it is not working and. After compilation when 1 is chosen it scroll the question enter name of the text file name to display. when 0 is chosen the program does the same.
Many thanks
#include <stdlib.h>
#include <stdio.h>
#define BUFSIZE 100
main()
{
char buf[BUFSIZE];
char filename[60];
FILE *fp;
int reply;
printf( "Enter 1 to select file to display 0 to exit " );
scanf("%d", &reply);
while( reply = 1 )
puts( "Enter name of text file to display: " );
gets(filename);
/* Open the file for reading. */
if ( ( fp = fopen(filename, "r")) == NULL )
{
fprintf( stderr, "Error opening file.\n" );
exit(1);
}
/* If end of file not reached, read a line and display it.*/
while( !feof(fp) )
{
fgets( buf, BUFSIZE, fp);
printf( "%s", buf );
}
fclose(fp);
return (0);
}