Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C VisualStudio读取垃圾字符_C_Visual Studio - Fatal编程技术网

C VisualStudio读取垃圾字符

C VisualStudio读取垃圾字符,c,visual-studio,C,Visual Studio,我试图读取test.vert文件,但VS在字符串缓冲区的开头一直给我一些垃圾字符,如下所示: 我必须将指针移到3个位置,以获得正确的字符串,使所有内容都能正常工作。这里发生了什么 这里有一个文件读取函数。我先试了一下我的,然后有几个人在网上复制,但结果都一样: char* filetobuf(char *file) { FILE *fptr; long length; char *buf; fptr = fopen(file, "r"); /* Open fi

我试图读取
test.vert
文件,但VS在字符串缓冲区的开头一直给我一些垃圾字符,如下所示:

我必须将指针移到3个位置,以获得正确的字符串,使所有内容都能正常工作。这里发生了什么

这里有一个文件读取函数。我先试了一下我的,然后有几个人在网上复制,但结果都一样:

char* filetobuf(char *file)
{
    FILE *fptr;
    long length;
    char *buf;

    fptr = fopen(file, "r"); /* Open file for reading */
    if (!fptr) /* Return NULL on failure */
        return NULL;
    fseek(fptr, 0, SEEK_END); /* Seek to the end of the file */
    length = ftell(fptr); /* Find out how many bytes into the file we are */
    buf = (char*)calloc(length + 1,1); /* Allocate a buffer for the entire length of the file and a null terminator */
    fseek(fptr, 0, SEEK_SET); /* Go back to the beginning of the file */
    fread(buf, length, 1, fptr); /* Read the contents of the file in to the buffer */
    fclose(fptr); /* Close the file */
    buf[length] = 0; /* Null terminator */

    return buf; /* Return the buffer */
}

可能只是unicode字节顺序标记(编辑器可以对您隐藏它)?

可能只是unicode字节顺序标记(您的编辑器可以对您隐藏它)?

可能就是这样。我创建的文本文件是使用VS并安装了NShader:。我删除了它,用记事本创建了一个新文件,得到了正确的文本字符串。也许我应该用一个真正的文本编辑器来编辑数据文件,也许就是这样。我创建的文本文件是使用VS并安装了NShader:。我删除了它,用记事本创建了一个新文件,得到了正确的文本字符串。也许我应该使用一个真正的文本编辑器来编辑数据文件。