⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fopen.c

📁 里面包含很多c语言的源码
💻 C
字号:
/* Demonstrates the fopen() function. */
#include <stdlib.h>
#include <stdio.h>

int main( void )
{
   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 = getc(stdin)) == '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 = getc(stdin)) == 'x')
                break;
            else
                continue;
        }
    }
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -