home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tyc
/
list16_1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-16
|
1KB
|
45 lines
/* Demonstrates the fopen() function. */
#include <stdio.h>
main()
{
FILE *fp;
char ch, filename[40], mode[4];
while (1)
{
/* Input filename and mode. */
printf("\nEnter a filename: ");
gets(filename);
printf("\nEnter a mode (max 3 characters): ");
gets(mode);
/* Try to open the file. */
if ( (fp = fopen( filename, mode )) != NULL )
{
printf("\nSuccessful opening %s in mode %s.\n",
filename, mode);
fclose(fp);
puts("Enter x to exit, any other to continue.");
if ( (ch = getch()) == 'x')
break;
else
continue;
}
else
{
fprintf(stderr, "\nError opening file %s in mode %s.\n",
filename, mode);
puts("Enter x to exit, any other to try again.");
if ( (ch = getch()) == 'x')
break;
else
continue;
}
}
}