OneCompiler

slip2

221

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

int main() {
char filename[256];
printf("Enter the file name: ");
scanf("%s", filename);

DIR *dir;
struct dirent *entry;
int found = 0;

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

while ((entry = readdir(dir)) != NULL) {
    if (strcmp(entry->d_name, filename) == 0) {
        found = 1;
        break;
    }
}

closedir(dir);

if (found) {
    printf("File '%s' is present in the current directory.\n", filename);
} else {
    printf("File '%s' is not found in the current directory.\n", filename);
}

return 0;

}