ls命令以这种格式打印时间:
Aug 23 06:07
Run Code Online (Sandbox Code Playgroud)
我如何转换,从接收到的时间stat()的mtime()这个格式的本地时间?
我在linux中使用lseek()从头到尾遍历一个文本文件。如何检查偏移位置是否已到达文件的开头。
PS 我不是在寻找使用文件大小来手动跟踪偏移量的解决方案。
我最好的猜测是,当您从已经平衡的AVL树插入或删除一个元素时,一次旋转总是足以平衡AVL树.
一次轮换总是足够吗?一个例子将有助于需要多次轮换.
PS:我将RL/LR旋转计为仅一次旋转.
我试图在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
分段故障(核心转储)
我试图打印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.仍然没有工作......
请问功能qsort()在stdlib.h实际使用快速排序算法,顾名思义?