小编Gav*_* Z.的帖子

System.err有什么意义?

在UNIX中,我应该编写一个Java文件,将"EXIT 1"打印到标准错误,然后以状态1退出.

这是我的方法..

System.err.println("EXIT 1");
System.exit(1);
Run Code Online (Sandbox Code Playgroud)

这是我应该做的吗?

如果是这样,我怎么能在Unix shell中使用它?当我在bash中编译并运行它时,它只打印"EXIT 1"(所以它与System.out.println做同样的事情,我为什么要使用"err"?).这里的"标准错误"是什么?

java unix bash stderr

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

C中的分段错误(核心转储)?

该程序基本上搜索文件中的字符串,然后根据提供的选项生成输出.

例如,在命令行上,

cmatch -i hello helloworld.txt

即使我注释掉所有printf语句,我仍然会遇到分段错误.但我是C的新手,我在这里找不到任何不合适的指针..帮助?

#include <errno.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>

int exit_status = EXIT_SUCCESS;

bool checkIfMatch(char *string, FILE *file) {

    while (true) {
        char buff[1024];
        fgets(buff, 1024, file);
        if (buff == NULL)
            break;
        if (strcmp(string, strstr(buff, string)) == 0)
            return true;
    }
    return false;

}


bool checkIfMatchIgnoreCase(char *string, FILE *file){
    while (true) {
        char buff[1024];
        fgets(buff, 1024, file);
        if (buff == NULL)
            break;
        if (strcasecmp(string, strstr(buff, string))== 0)
            return …
Run Code Online (Sandbox Code Playgroud)

c pointers segmentation-fault

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

"expr1?expr 2:expr 3"的解释?

我在这里很难理解这句话:

for( int i=0; i< out_length; i++){

     int num=i < length_a ? array_a[i] : 0;

...
...
Run Code Online (Sandbox Code Playgroud)

我用Google搜索的内容:

expr1?expr2:expr3

如果expr1计算为非零值,则计算expr2,否则计算expr3.整个表达式的值是expr2或expr3的值(这意味着expr2和expr3的类型必须相同).

但是我仍然感到困惑,如果你能把这个陈述变成一些if-else块会很有帮助,谢谢你的帮助..

c operators

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

标签 统计

c ×2

bash ×1

java ×1

operators ×1

pointers ×1

segmentation-fault ×1

stderr ×1

unix ×1