C產生並開啟連續號碼檔案

#include <stdio.h>
#define PATH_BUF_SIZE 2048

int main () {
    int i;
    char tmp_path[PATH_BUF_SIZE] = {0};
    FILE* out;
    
    for (i = 0; i <10; ++i) {
        snprintf(tmp_path, PATH_BUF_SIZE-1, "file_%d.txt", i);
        out = fopen(tmp_path, "wb");
        if (out == NULL) {
            fprintf(stderr, "error open file=%s\n", tmp_path);
            continue;
        }
        fclose(out);
    }    
    return 0;
}

留言