第2个回答 2011-12-20
int ReadData(char* fileName, DATA* head)
{
FILE *fp;
DATA* currentRow;
DATA* row1, row2, row3;
if ((fp = fopen(fileName, "r")) == NULL)
{
printf("Cannot open %s!", fileName);
return 1;
}
row1 = (DATA*)malloc(sizeof(DATA));
row2 = (DATA*)malloc(sizeof(DATA));
row3 = (DATA*)malloc(sizeof(DATA));
memset(row1, 0, sizeof(DATA));
memset(row2, 0, sizeof(DATA));
memset(row3, 0, sizeof(DATA));
currentRow = row1;
while (fscanf(fp, "%s,%s,%s", &(row1->data), &(row2->data), &(row3->data)) != EOF)
{
currentRow = row1;
row1->nrow = row2;
row2->nrow = row3;
row1 = (DATA*)malloc(sizeof(DATA));
row2 = (DATA*)malloc(sizeof(DATA));
row3 = (DATA*)malloc(sizeof(DATA));
memset(row1, 0, sizeof(DATA));
memset(row2, 0, sizeof(DATA));
memset(row3, 0, sizeof(DATA));
currentRow->ncol = row1;
}
delete row1;
delete row2;
delete row3;
row1 = NULL;
return 0;
}本回答被提问者采纳
第3个回答 2011-12-18
C语言我不懂怎么写,我只有思路(办法有好多,你先可以读取它一行,把这行读出来以后用分割符隔开,用数组来接收,会有三个数组分别为A(0),A(1),A(2),后面的就是把A(0),A(1),A(2)加起来,中间用“→”