我通过命令行输入接受路径.
当我做
dir=opendir(args[1]);
Run Code Online (Sandbox Code Playgroud)
它没有进入循环......即dir==null......
如何将命令行输入传递给dir指针?
void main(int c,char **args)
{
DIR *dir;
struct dirent *dent;
char buffer[50];
strcpy(buffer, args[1]);
dir = opendir(buffer); //this part
if(dir!=NULL)
{
while((dent=readdir(dir))!=NULL)
printf(dent->d_name);
}
close(dir);
}
./a.out /root/TEST is used to run the program..
./a.out --> to execute the program
/root/TEST --> input by the user i.e valid path
Run Code Online (Sandbox Code Playgroud) 我似乎无法弄清楚如何在 C 程序中运行 cmd 程序。
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char educode[100];
printf("Welcome To ACE-IT Edu Software!\n");
printf("\nPlease Type An Educator Code and then press enter.");
printf("\nEducator Code: ");
gets(educode);
if(educode == 5678){
system("mkdir test");
} else {
printf("\nSorry, thats not a valid Educator Code. To buy an Educator Code, go to https://www.ace-it.edu");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)