如何从文件中读取字符并将其拆分为两个16位?

时间:2014-03-19 14:08:21

标签: c

我想读取文件的d个字符并将其分成两个16位,例如:

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

怎么做?

INSTEAD OF TEXT [0]和TEXT [1] PREDEFINED VALUES我想要2从文件中读取字符并将其分成2页

1 个答案:

答案 0 :(得分: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) ;