如何为电子邮件管理器创建新文件夹,我有此代码,但它不起作用。

 void create_folder() {
   int check;
   char * dirname;
   clrscr();
   printf("Enter a directory path and name to create a folder (C:/name):");
   gets(dirname);
   check = mkdir(dirname);

   if (!check)
     printf("Folder created\n");

   else {
     printf("Unable to create folder\n");
     exit(1);
   }
   getch();
   system("dir/p");
   getch();
 }

最佳答案

使用这个:

 void create_folder() {
   int check;
   char dirname[128];
   clrscr();
   printf("Enter a directory path and name to create a folder (C:/name):");
   fgets(dirname, sizeof(dirname), stdin);
   check = mkdir(dirname);

   if (!check)
     printf("Folder created\n");

   else {
     printf("Unable to create folder\n");
     exit(1);
   }
   getch();
   system("dir/p");
   getch();
 }

您的dirname字符串未分配,请改用char数组。

关于c - 如何在C中创建文件夹,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48648872/

10-11 18:30