fopen 自动完成更改目录
fopen auto complete changing directory
在 Debian 中开发 C 程序,我需要访问一个目录,该目录末尾的数字偶尔会更改。从命令提示符访问时,我可以使用 Tab 键完成或使用 *,如何使用 fopen 或其他方法从 C 程序执行此操作?
pwm = fopen("/sys/devices/ocp.3/pwm_test_P8_19.15/duty // this is the changing directory
pwm = fopen("/sys/devices/ocp.3/pwm_t*/duty // this did not work
使用 stdio.h、stdlib.h、unistd.h
int k = 0;
char pwm_path[100];
for (k = 14; k < 20; k++)
{
sprintf( pwm_path, "/sys/devices/ocp.3/pwm_test_P8_19.%d/period", k );
puts(pwm_path); //debug
if (access( pwm_path, F_OK ) == 0) // if it finds path, then = 0
{
//printf("Files does exists, %d\n", k); // debug
pwm = fopen( pwm_path, "w" );
fseek(pwm,0,SEEK_SET);
fprintf(pwm,"20000000"); // pulse period in uS
fflush(pwm); // flush free up memory
break; // break out of loop once found
}
}
在 Debian 中开发 C 程序,我需要访问一个目录,该目录末尾的数字偶尔会更改。从命令提示符访问时,我可以使用 Tab 键完成或使用 *,如何使用 fopen 或其他方法从 C 程序执行此操作?
pwm = fopen("/sys/devices/ocp.3/pwm_test_P8_19.15/duty // this is the changing directory
pwm = fopen("/sys/devices/ocp.3/pwm_t*/duty // this did not work
使用 stdio.h、stdlib.h、unistd.h
int k = 0;
char pwm_path[100];
for (k = 14; k < 20; k++)
{
sprintf( pwm_path, "/sys/devices/ocp.3/pwm_test_P8_19.%d/period", k );
puts(pwm_path); //debug
if (access( pwm_path, F_OK ) == 0) // if it finds path, then = 0
{
//printf("Files does exists, %d\n", k); // debug
pwm = fopen( pwm_path, "w" );
fseek(pwm,0,SEEK_SET);
fprintf(pwm,"20000000"); // pulse period in uS
fflush(pwm); // flush free up memory
break; // break out of loop once found
}
}