简体   繁体   English

用于在阵列中存储ttyUSB *设备的C程序

[英]C Program to Store ttyUSB* devices in an array

AM having a C program which uses system to list /dev/ttyUSB* devices how can I store them in an array and process. AM有一个C程序,该程序使用系统列出/ dev / ttyUSB *设备,如何将它们存储在数组和进程中。

#include <stdio.h>
#include <stdlib.h>

int main()
{

    system("ls /dev/ttyUSB*");
    printf("Done");
    exit(0);
}

Using system for these things is a bad idea. 为这些事情使用system是一个坏主意。

First of all, you have to Parse the output of ls , which you should avoid. 首先,您必须解析ls的输出,应避免这样做。

Apart from that, this will be quite inefficient. 除此之外,这将是非常低效的。 starting programs is rather slow, but you are running a program (written in C), that starts another program (written in C) which calculates something and renders this something into a human-readable form, and then you have to parse the human-readable form to find out what the original something was... 启动程序是相当缓慢的,但你运行的程序(用C语言编写),启动其他程序(用C语言编写),计算的东西 ,呈现此事情成为人类可读的形式,然后你必须解析人-可读的表格,以找出原始的东西什么 ...

A better way is to do the shortcut can "calculate the something " directly: 更好的方法是执行快捷方式可以直接“计算某些内容 ”:

check out glob 签出glob

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM