OneCompiler

slip13

118

#include <stdio.h>
#include <dirent.h>
#include <string.h>

int isFileExists(const char *filename) {
DIR *dir;
struct dirent *entry;

dir = opendir(".");
if (dir == NULL) {
    perror("Error opening directory");
    return 0;
}

while ((entry = readdir(dir)) != NULL) {
    if (entry->d_type == DT_REG && strcmp(entry->d_name, filename) == 0) {
        closedir(dir);
        return 1;  // File found
    }
}

closedir(dir);
return 0;

}

int main() {
char filename[100];

printf("Enter the filename: ");
scanf("%s", filename);

if (isFileExists(filename)) {
    printf("The file '%s' exists in the current directory.\n", filename);
} else {
    printf("The file '%s' does not exist in the current directory.\n", filename);
}

return 0;

}