小编kBi*_*sla的帖子

如何以特定格式打印time_t?

ls命令以这种格式打印时间:

Aug 23 06:07 
Run Code Online (Sandbox Code Playgroud)

我如何转换,从接收到的时间stat()mtime()这个格式的本地时间?

c linux time timezone ls

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

如何使用 lseek 检查文件中的当前偏移位置?

我在linux中使用lseek()从头到尾遍历一个文本文件。如何检查偏移位置是否已到达文件的开头。

PS 我不是在寻找使用文件大小来手动跟踪偏移量的解决方案。

c linux file-io file

5
推荐指数
1
解决办法
9954
查看次数

平衡AVL树需要多次旋转?

我最好的猜测是,当您从已经平衡的AVL树插入或删除一个元素时,一次旋转总是足以平衡AVL树.

一次轮换总是足够吗?一个例子将有助于需要多次轮换.

PS:我将RL/LR旋转计为仅一次旋转.

tree binary-tree rotation avl-tree data-structures

5
推荐指数
2
解决办法
6604
查看次数

如何在c中正确使用scandir()?

我试图在char**变量中存储文件列表.

scandir()完成正常,但在尝试打印char**时出现分段错误.

这是代码:

int main()
{
    char** fileList;
    int noOfFiles;
    char* path = ".";
    makeList(&fileList, &noOfFiles, path); 
    return 0;
}

void makeList(char ***fileList, int* noOfFiles, char* path){
    struct dirent **fileListTemp;
    *noOfFiles = scandir(path, &fileListTemp, NULL, alphasort);
    int i;
    fileList = (char***)malloc(sizeof(char***));
    *fileList = (char**)malloc(*noOfFiles * sizeof(char*));
    printf("total: %d files\n",*noOfFiles);
    for(i = 0; i < *noOfFiles; i++){
        *fileList[i] = (char*)malloc(strlen(fileListTemp[i] -> d_name) *sizeof(char));
        strcpy(*fileList[i], fileListTemp[i] -> d_name);
        printf("%s\n",*fileList[i]);
    }
    return;
}
Run Code Online (Sandbox Code Playgroud)

打印2个文件名后,这会出现分段错误.

输出:

总计:27个档案.

..

.jv

分段故障(核心转储)

c linux string malloc scandir

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

为什么java.Math.BigInteger在一定限制后出错?

我试图打印2 ^ n中的数字总和,n = 1到1000.这就是我所做的.

public static void main(String[] args) {
    int n = 1000;
    for (int i = 1; i < n; i++) {
        BigInteger power = BigInteger.valueOf((int)Math.pow(2, i));
        int sum = 0;
        while (power.intValue() > 0) {
            sum += power.intValue() % 10;
            power = power.divide(BigInteger.valueOf(10));
        }
        System.out.print(sum + "  ");
    }
}
Run Code Online (Sandbox Code Playgroud)

它只能工作到大约2 ^ 30左右,然后打印相同的结果,46,其余的.

我在C中使用"long long"尝试过类似的东西,并且在类似限制之后打印0.

根据答案,我改变了

BigInteger power = BigInteger.valueOf((int)Math.pow(2, i));
Run Code Online (Sandbox Code Playgroud)

BigInteger power = BigInteger.valueOf(2).pow(i);
Run Code Online (Sandbox Code Playgroud)

和46改为0.就像C.仍然没有工作......

java biginteger

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

qsort()使用哪种排序算法?

请问功能qsort()stdlib.h实际使用快速排序算法,顾名思义?

c sorting optimization qsort

-3
推荐指数
1
解决办法
300
查看次数