Mercurial > codedump
view kmbscreens/randfile.c @ 115:f10492e8720b
kemonopartydownloader.py: add youtube downloader stubs and dump json to disk
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 23 Jan 2023 23:58:22 -0500 |
parents | e5ea19b94639 |
children |
line wrap: on
line source
#include <stdio.h> #include <dirent.h> #include <stdlib.h> #include <time.h> int main(void) { srand((unsigned)time(NULL)); DIR *d; struct dirent *dir; d = opendir("E:\\Movies\\Anime\\Kill Me Baby"); int count = 0; char** ret = NULL; if (d) { while ((dir = readdir(d)) != NULL) { char* dot = strrchr(dir->d_name, '.'); if (dot && !strcmp(dot, ".mkv")) { ret = realloc(ret, (count+1)*sizeof(char*)); if (ret == NULL) return 1; ret[count] = calloc(strlen(dir->d_name), sizeof(char)); if (ret[count] == NULL) { free(ret); return 2; } strncpy(ret[count], dir->d_name, strlen(dir->d_name)*sizeof(char)); ret[count][strlen(dir->d_name)] = '\0'; count++; } } closedir(d); } printf("%s\n", ret[rand() % count]); for (int i = 0; i < count; i++) free(ret[i]); free(ret); return 0; }