我有一个文件data.dat
HI5 LO2
我想从中读取5和2,并将它们存储为uint16s。我写过
#include <stdio.h>
int main()
{
unsigned short int high;
FILE *pFile;
pFile = fopen("data.dat", "r");
int c;
while(c != 'I')
{
c = fgetc(pFile);
}
high = while(c != ' ')
{
c = fgetc(pFile);
}
printf("%i\n", high);
if(c == ' '){puts("we read until 1st line space");}
else{puts("we didn't read until 1st line space");}
fclose(pFile);
return 0;
}
高分配给while循环,因为我们可能得到更大的数字,如10,但这样做会产生错误。我如何从文本文件中的值分配整数?