c - Creating Pipes with array in loop
问题描述
I need to create 10 pipes in C. In order to make them work I need to create 10 int arrays of size 2? Or can I just declare an array sized 20 and then give the pipe the adress where each pipe should start? If I have to create 10 is there any way i can create them in a loop and get kind of this result?
for(i=0; i<10; i++){
vec0[2]; //create array vec0, vec1, vec2....
pipe(vec0);
}
Is even an array the best way to do this?
解决方案
int
您可以使用如下所示的二维数组。
int fds[10][2];
for(i=0; i<10; i++){
pipe(fds[i]);
}
wherefds[i][0]
代表读结束,fds[i][1]
代表写结束。
如果您不想使用二维数组,则可以int
如下声明 20 s 的数组,并使用基于偏移的方法来传递和读取fd's
.
int fds[20];
for(i=0; i<10; i++){
pipe(fds+i*2);
}
然后fds[i*2]
代表读结束,fds[i*2+1]
代表写结束。
推荐阅读
- encryption - Cassandra 4 和密码套件
- html - 如何左右滑动点击按钮
- browser - 是否有将 3d 模型插入照片的工具或 API 服务?
- python - 如何将数据放入 html 但看起来像 django 中的 excel 表?
- java - 如何避免在 sparkUI 中显示一些秘密值
- reactjs - 在运行时使用 Ant Design 在 React Gatsby 应用程序中动态更改 Less 变量
- java - 无法在 Visual Studio Code 中运行 Java 代码
- angular - 通过浏览器访问延迟加载模块时,运行时编译器未加载角度 8
- python - 带有函数的 Python 解释器序列
- python - 查找字符串中子字符串的最佳匹配