2016-08-16 9 views
0

ジャンク文字を読み込みますが、VSは、このように私の文字列バッファの先頭に私にいくつかのジャンク文字を与え続け:Visual Studioは、私が<code>test.vert</code>ファイルから読み取るしようとした

junk_chars

私が移動しなければなりませんでしたポインタ3は、正しく動作するようにすべての文字列を取得するために離れて配置されます。ここで何が起きてるの?

ここには1つのファイル読み取り機能があります。私はその後、いくつか他の人がインターネット上でコピーし、最初の鉱山を試してみましたが、結果は同じです。

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 */ 
} 

答えて

3

たぶんそれだけのUnicodeバイト順マーク(エディタあなたからそれを隠すことができますが)ですか? https://en.wikipedia.org/wiki/Byte_order_mark

+0

おそらくこれが該当します。私が作成したテキストファイルは、NShaderがインストールされたVSを使っていました:https://github.com/samizzo/nshader/。私はそれを削除し、メモ帳を使用して新しいファイルを作成し、正しいテキスト文字列を得ました。おそらく、私はちょうどデータファイルのための実際のテキストエディタを使用する必要があります。 –

関連する問題