2014-03-19 58 views
-5

我想讀取文件的d個字符,並拆分成兩個16位比方說:如何從文件中讀取字符並將其拆分爲兩個16位?

text[1]=0x7469206564616d20; 
text[2]=0x7469206564616d20; 

如何做到這一點?

不是文本[0]和文本[1]預定義值I WANT IT 2個READ d個字符從一個文件,把它分解IN2形成

+0

怎麼辦你的意思是「分成兩個16位」?你可以在上面給出的例子中顯示你需要的輸出嗎? –

+0

拆分爲xample:text [1] = 0x7469206564616d20;和text [2] = 0x7469206564616d20 – user3437968

+1

那麼輸入是什麼(因爲這兩個是相同的)? – fritzone

回答

0

你可能想這樣的:

u64 text[2] ; 

FILE *input = fopen("myfile.data", "r") ; 

if (input == NULL) 
{ 
    printf ("Unable to open file\n") ; 
    return 1 ; 
} 

while (!feof(input)) 
{ 
    int charsread ; 
    charsread = fread(text, 16, 1, input) ; // read at most 16 bytes into the text array 

    // process your text array here 
    // charsread contains the number of characters actually read 
    //  this can be less than 16 if the total file length is not a 
    //  multiple of 16. You mus deal with that. 

} 

fclose(input) ; 
+0

將dis文件分割爲兩個text0和text1 ?? – user3437968

+0

文件的前8個字符進入'text [0]',文件的後8個字符進入'text [1]'。 –

+0

如果超過16個字符怎麼辦?需要某種循環然後 – user3437968

相關問題