小编aus*_*tin的帖子

在C中获得终端宽度?

我一直在寻找一种从我的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)

c linux terminal width

84
推荐指数
3
解决办法
7万
查看次数

最好的c音频库linux

我想知道是否有人对他们认为最好的Linux音频库有什么看法.我刚刚学习并正在试验libao上的音频输出.

编辑:现在我正在尝试做的就是输出频率音调.

c linux audio

6
推荐指数
1
解决办法
9150
查看次数

在C中连接字符串

我想知道是否有一种方法可以为字符串添加值,而不是像1 + 1 = 2但像1 + 1 = 11.

c string concatenation

3
推荐指数
2
解决办法
1万
查看次数

收集数字并打印它们

我想要完成的是生成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)

c random string-concatenation

0
推荐指数
1
解决办法
111
查看次数