Why this codes have opening the file problem on C?

I’m coding on vscode on macos macbook. And I have some problems with opening the file.
I have no idea why file is not read. The text file is in same directory. but the result of Unix executable file is:

scheduling.txt
file open error: 2
Could not open data file: No such file or directory
zsh: abort      

File directory

As you can see, the name is no problem.

// Priority.h
#ifndef DATA_H_
#define DATA_H_

// Process Structure
typedef struct {
    int processID;
    int arrivalTime;
    int burstTime;
    int priority;
}Process;

// Result Structure
typedef struct {
    int processID;
    int burstTime;
    int waitingTime;
} ResultElement;


int OpenFile(const char* filename, Process *process[]); // File open
Process Initialize (Process* process, int i); // Intialize Queue
Process* ReadyQueueGenerator (int); // Generate Ready Queue
void ShowResult (ResultElement process); // Show Reulst
void SchedulingAlgorithm (Process process[], int); // Run Scheduling Algorithm
void Sort(Process process[], int); // Sort Process

#endif
// main.c
// Priority Scheduling Algorithm
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "Priority.h"

// Sort by Arrival Time
void Sort(Process process[], int numProcess) {
    Process temp;
    for (int i = 0; i < numProcess; i++) {
        for (int j = i+1; j < numProcess; j++) {
            if (process[i].arrivalTime > process[j].arrivalTime) {
                temp = process[i];
                process[i] = process[j];
                process[j] = temp;
            }
        }
    }
}

int main() {
    Process *process = NULL;
    int numProcess = OpenFile("scheduling.txt", &process);
    if (numProcess == -1) {
        printf("Failed to open file.n");
        return EXIT_FAILURE;
    }

    // List of process
    printf("Inputn");
    printf("---------------------------------------------------------n");
    printf("Process IDt Arrival Timet Burst Timet Priorityn");
    printf("---------------------------------------------------------n");
    for (int i = 0; i < numProcess; i++) {
        printf("%2dtt %2dtt %2dtt %2dn", process[i].processID, process[i].arrivalTime, process[i].burstTime, process[i].priority);
    }

    // Sort by Arrival Time
    Sort(process, numProcess);

    // Run Scheduling Algorithm
    SchedulingAlgorithm(process, numProcess);

    free(process);
    return 0;

    
}
// FileOpen.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include "Priority.h"

// Open file function
int OpenFile(const char* filename, Process **process) {
    FILE *file;
    int line = 0;
    int i = 0;

    printf("%sn", filename);

    // Open file function
    file = fopen(filename, "r");
    if (file == NULL) {
        printf("file open error: %dn", errno);
        perror("Could not open data file");
        abort();
    }

    char bin[20] = {0, };
    while (fgets(bin, sizeof(bin), file) != NULL) {
        line++;
    }

    fseek(file, 0, SEEK_SET);

    *process = (Process*)malloc(sizeof(Process) * line);
    if (process == NULL) {
        fprintf(stderr, "Memory Allocation failure.n");
        return -1;
    }


    while (fscanf(file, "%s %d %d %d %d", bin, &(*process)[i].processID, &(*process)[i].arrivalTime, &(*process)[i].burstTime, &(*process)[i].priority) != EOF) {
        i++;
    }
    
    
    fclose(file);
    return line;
}

I think I wrote codes properly but the file is not opened

New contributor

권기범 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật