- 论坛徽章:
- 0
|
#include<stdio.h>
#include<stdlib.h>
main()
{
FILE *fp;
char filename[40],mode[4];
while (1)
{
/*input filename and mode.*/
printf("Enter a filename: \n");
gets(filename);
printf("Enter a mode (max 3 characters): \n");
gets(mode);
/* Try to open the file */
if ((fp=fopen(filename,mode)) != NULL)
{
printf("Successful opening %s in mode %s.\n",filename,mode);
fclose(fp);
puts("Enter x to exit,any other to continue.");
if((getc(stdin)) == 'x')
break;
else
continue;
}
else
{
fprintf(stderr,"Error opening file %s in mode %s.\n",filename,mode);
puts("Enter x to exit,any other to try again.");
if ((getc(stdin)) == 'x')
break;
else
continue;
}
}
}
[ 本帖最后由 鬼才小科 于 2009-5-11 09:58 编辑 ] |
|