#include <stdio.h>
#include <stdlib.h>
int main() {
    FILE *fps[3];
    char *filenames[] = {"file1.txt", "file2.txt", "file3.txt"};
    int i, openCount = 0;

    // 批量打开文件
    for (i = 0; i < 3; i++) {
        fps[i] = fopen(filenames[i], "w");
        if (fps[i] == NULL) {
            printf("打开%s失败！\n", filenames[i]);
            // 关闭已打开的文件
            for (int j = 0; j < openCount; j++) {
                fclose(fps[j]);
            }
            return 1;
        }
        openCount++;
    }

    // 批量关闭文件
    for (i = 0; i < 3; i++) {
        fclose(fps[i]);
    }
    printf("所有文件打开并关闭成功！\n");
    return 0;
}