数据读取及操作,请高手帮忙!
有这样一个txt数据:4000
By xp
36.14898 36.14898 36.14898 90.00 90.00 90.00
Cu 0.90154 0.90288 0.90230
Cu 0.90823 2.71154 2.71052
Cu 2.71029 0.90193 2.71217
Cu 2.70881 2.71222 0.90372
Cu 0.90322 0.90311 4.51897
................
1.读入文件,并把前3行完整的输入到新的txt文件中
2. 第三行的前三个数赋值与boxx,boxy,boxz. 其他的程序会调用.
3. 读入第4行之后的所有数据到链表.
4. 对第4行之后的第2,3,4列的数据操作后,输出新的一列数据.
5. 输出的文件应为如下格式:
4000
By xp
36.14898 36.14898 36.14898 90.00 90.00 90.00
Cu 0.90154 0.90288 0.90230 0.2222
Cu 0.90823 2.71154 2.71052 0.2222
Cu 2.71029 0.90193 2.71217 0.12323
Cu 2.70881 2.71222 0.90372 0.334342
Cu 0.90322 0.90311 4.51897 0.72787
................
下面是我写的输入输出函数和定义的链表, 为什么输出的结果少了很多行,并且最后一列也没有输出?请高手解答!!!!!
typedef struct //Define structure to contain all data read from input file;
{
char atomname;
VALUE_TYPE data[DATA_COUNT + 1]; //Add 1, so that c can be outputed;
struct AtomType* pNext;
} AtomType;
AtomType* Input( FILE* pIn, FILE* pOut )
{
char szLine[MAX_LINE];
int i;
AtomType* atomArr = NULL;
AtomType* pAtom;
for (;!feof(pIn);)
{
fgets(szLine, MAX_LINE, pIn);
fprintf(pOut, "%s", szLine);
fgets(szLine, MAX_LINE, pIn);
fprintf(pOut, "%s", szLine);
fgets(szLine, MAX_LINE, pIn);
fprintf(pOut, "%s", szLine);
boxx = atof(szLine);
boxy = atof(szLine + 9);
boxz = atof(szLine + 18);
fgets(szLine, MAX_LINE, pIn);
if (atomArr == NULL)
{
atomArr = (AtomType*)malloc(sizeof(AtomType));
pAtom = atomArr;
}
else
{
pAtom->pNext = (struct AtomType*)malloc(sizeof(AtomType));
pAtom = (AtomType*)pAtom->pNext;
}
pAtom->pNext = NULL;
fscanf(pIn, "%s", &(pAtom->atomname));
for (i = 0; i < DATA_COUNT; i++)
{
fscanf(pIn, "%f", pAtom->data + i);
}
fgets(szLine, MAX_LINE, pIn);
}
return atomArr;
}
void Output(FILE* p, AtomType* atomArr)
{
int i;
AtomType* pAtom;
for (pAtom = atomArr; pAtom != NULL; pAtom = (AtomType*)pAtom->pNext)
{
if (pAtom->data[DATA_COUNT] > 0.01)
{
//continue;
}
fprintf(p, "%c", pAtom->atomname);
for (i = 0; i < DATA_COUNT + 1; i++)
{
fprintf(p, " %.5f", pAtom->data[i]);
}
fwrite("\n", 1, 1, p);
//fprintf(p, "%c", (char)0x0A);
}
}