c - 在我的程序中读取标准输入会返回 ��,଄��?这是什么

标签 c stdin

我试图了解如何修复我的代码,但它返回了一堆奇怪的字符。这是什么?我该如何解决它?

涉及 2 个程序。第一个读取 stdinput 并将该行发送到另一个程序,然后该程序单独解析和评估每个文件。当第二个程序尝试单独读取每个文件时,它会出错并返回无法读取文件“��,଄��”

为第一个程序提供 stdinput 的代码

while (fgets(tmpstring, 1024, stdin) && (tmpstring != NULL)) 
{
    fileName = tmpstring;

    write(report2access[1], fileName, (LINE_MAX* sizeof(char))+1);
    write(negreport2access[1], fileName, (LINE_MAX* sizeof(char))+1);

}

评估第二个程序中每个文件名的代码

while (fgets(tmpstring, 1024, stdin) && (tmpstring != NULL)) 
{
    fileName = tmpstring;

    //remove newline
    if ((pos=strchr(fileName, '\n')) != NULL)
        *pos = '\0';

    token = strtok(fileName, s);

    //walk through tokens
    while(token != NULL){
        access = lastAccess(token);

        if (num > 0){
            if(access > argvseconds){

                printf("%s\n", token); //#DEBUG
            }
        }

        else if (num < 0){
            if (access < argvseconds){
                printf("%s\n", token); //#DEBUG
            }
        }
        token = strtok(NULL, s);
    }
}

最佳答案

一般来说,它看起来像一个文件名,后面跟着一堆垃圾字节被写入 negreport2access[1]report2access[1] 然后是第二个程序正在尝试解析这些垃圾字节,就好像它们包含有效的文件名一样。

关于c - 在我的程序中读取标准输入会返回 ��,଄��?这是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28891074/

相关文章:

c - 修改用户输入文件路径以扫描C中同一目录中的文件

c - C 中的浮点和双指针

c - 在 C 中使用宏处理操作

multithreading - stdin、stdout 和 stderr 是共享的吗?

sockets - Node.js 端口同时监听和读取标准输入

javascript - MongoDB shell : reading a line from the console

c - 将两位数字打印为字符

c++ - 将文本光标移动到特定的屏幕坐标?

c - 从txt文件中取出表并将其存储到c中的数组中

超过 4096 字节的 Python stdin readline?