【发布时间】:2021-07-03 11:03:51
【问题描述】:
我将所有文件名(在本例中为文件夹 /Windows/Fonts/ 中的所有文件)放入 char File_Names。 Menawhile 名称也会被渲染,但是在我将所有内容都放入 char 之后(当 while 结束时),我尝试访问它并在其他东西中使用其中一个名称(这发生在 while 之后),但是我尝试的每一个指针只给出文件夹中的最后一个文件(这意味着它只有最后一个指针)。如何保留所有不同的文件名并在一段时间后使用它们? 这是我的程序的一个片段:
//-------------------- List files start
int File_Name_Y = Font_Window_Y+35-Mouse_Scroll*10;
char *File_Names[4096];
struct dirent *entry;
DIR *dir = opendir("/Windows/Fonts");
int t = 1;
while ((entry = readdir(dir)) != NULL)
{
t += 1;
File_Names[t] = entry->d_name;
if (File_Name_Y <= Font_Window_Y+H-65 && File_Name_Y >= Font_Window_Y+30)
{
draw_text (Font_Window_X+15, File_Name_Y, File_Names[t], {1, 1, 1}, 1.5);
}
File_Name_Y += 20;
}
closedir(dir);
//------------------ List files end
if (use_button (SelectFontButton))
{
if (Mouse_Pressed)
{
Mouse_Pressed = 0;
char Font_Path[1024];
strcpy (Font_Path, "/Windows/Fonts/");
strcat(Font_Path, File_Names[3]);
strcpy (Global_Font, Font_Path);
printf (Global_Font);
}
}
【问题讨论】: