-
Notifications
You must be signed in to change notification settings - Fork 10
/
File_-_ReadDirIntoCharArray.c
79 lines (64 loc) · 2.42 KB
/
File_-_ReadDirIntoCharArray.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "raylib.h"
#include <dirent.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib example.");
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Out char where we store the filenames.
char files[10024][PATH_MAX];
int numfiles=0;
// Here we read the current dir(where this example is run)
// and copy the filename into the files char array.
DIR *d;
struct dirent *dir;
d = opendir(".");
if (d)
{
while ((dir = readdir(d)) != NULL)
{
strcpy(files[numfiles],dir->d_name);
numfiles++;
}
closedir(d);
}
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText(FormatText("Number of files in dir : %i",numfiles),10,10,20,BLACK);
// Draw the first chunk of the dir to the screen.
if(numfiles>0){
int x=0;
int y=20;
for(int i=0;i<numfiles;i++){
DrawText(FormatText("%s",files[i]),10+x,10+y,10,BLACK);
y+=10;
if(y>screenHeight-50){
x+=200;
y=20;
}
}
}
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}