我有一个文件 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;
}
high 被分配给一个 while 循环,因为我们可能会得到更大的数字,比如 10,但是这样做会产生错误。如何从文本文件中的值分配整数?