我一直在寻找一种从我的C程序中获取终端宽度的方法.我一直想出的是:
#include <sys/ioctl.h>
#include <stdio.h>
int main (void)
{
struct ttysize ts;
ioctl(0, TIOCGSIZE, &ts);
printf ("lines %d\n", ts.ts_lines);
printf ("columns %d\n", ts.ts_cols);
}
Run Code Online (Sandbox Code Playgroud)
但每次我尝试我得到
austin@:~$ gcc test.c -o test
test.c: In function ‘main’:
test.c:6: error: storage size of ‘ts’ isn’t known
test.c:7: error: ‘TIOCGSIZE’ undeclared (first use in this function)
test.c:7: error: (Each undeclared identifier is reported only once
test.c:7: error: for each function it appears in.)
Run Code Online (Sandbox Code Playgroud)
这是最好的方法吗,还是有更好的方法?如果不是,我怎么能让它工作?
编辑:固定代码是
#include <sys/ioctl.h>
#include <stdio.h>
int main (void)
{
struct winsize …Run Code Online (Sandbox Code Playgroud) 我想知道是否有人对他们认为最好的Linux音频库有什么看法.我刚刚学习并正在试验libao上的音频输出.
编辑:现在我正在尝试做的就是输出频率音调.
我想知道是否有一种方法可以为字符串添加值,而不是像1 + 1 = 2但像1 + 1 = 11.
我想要完成的是生成100个随机0和1将它们全部添加到一个变量然后打印它.我现在所拥有的,我不知道如何工作.如果有人能解释我做错了什么,我将非常感激.
randstring (void){
int i;
int num;
char buffer[101];
i=100;
while(i>0, i--){
num = rand()%2;
strcpy(buffer, num);
}
return(buffer);
}
Run Code Online (Sandbox Code Playgroud)
我现在拥有的是:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main (void){
printf("%f", randstring());
}
randstring (void){
int num;
char buffer[101];
int i = 100;
while(i-- >= 0) buffer[i] = rand() % 2;
return(buffer);
}
Run Code Online (Sandbox Code Playgroud)