[問題] 鏈結串列+結構指標
各位高手大大好:
以下為小弟的程式碼,目的為將每個fin00%d.txt檔(各16筆10進位數字)
共有四個,用串列的方式,最後在一次輸出為一個48筆的out.txt檔
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#define size 160
void Read (char file_name[40]); //讀.txt副程式
struct node
{
unsigned char buffer_1D[size];
struct node *next;
};
typedef struct node Node;
Node *first, *current, *previous;
int main(void)
{
int i=0,j=0,n=0;
int Data_num=1;
char InName[40] ="fin000.txt";
//char OutNmae[40] ="fout000.txt";
for(Data_num=1;Data_num<=4; Data_num++)
{
sprintf(InName,"fin00%d.txt",Data_num);
//sprintf(OutNmae,"fout00%d.txt",Data_num);
current = (Node*)malloc(sizeof(Node*));
Read (InName); //讀.txt檔副程式
///----------------以下為串列部分-------------
current = (Node*)malloc(sizeof(Node*));
scanf("%d",current->buffer_1D);
if(Data_num==0)
{
first=current;
}
else
{
previous->next=current;
current->next=NULL;
previous=current;
}
}
current=first;
while(current!=NULL)
{
previous=current;
current=current->next;
free(previous);
}
//----------------------------------------
return 0;
}
void Read ( char file_name[40])
{
int i=0,j=0,n=0;
unsigned char in0;
unsigned char *input;
input = (unsigned char*)malloc(160*sizeof(void*));
FILE *fp_input;
fp_input = fopen(file_name,"rb");
if(fp_input == NULL)
{
printf( "\n Can't open file %s",file_name);
system("pause");
exit(0);
}
n=0;
while ((fscanf(fp_input, "%d\n",&in0))!=EOF)
{
*input=in0;
current=*input;//????????出現錯誤訊息
n++;
}
fclose(fp_input);
free(input);
}
小弟可以把每個.txt檔裡面的資訊一個一個讀出來,
但是沒有辦法把讀出來的資料讀進去指標結構current當中
以便利用串列把所有資料串起來,
在current=*input;會出現
error C2440: '=' : cannot convert from 'unsigned char' to 'struct node *'
Conversion from integral type to pointer type requires reinterpret_cast
, C-style cast or function-style cast
請各位救救我,我僵在這近四天了,
會這樣的目的是因為要應負將來資料庫不斷的存放
但是總不能每次都把程式打開來再改變一些陣列大小
所以做了這個小實驗
請各位好心人士幫幫忙,指點指點要如何改程式,或是給別的建議
我只為傳統的C而已.....XD
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.43.16.161
→
10/22 01:01, , 1F
10/22 01:01, 1F
推
10/22 01:01, , 2F
10/22 01:01, 2F
→
10/22 01:03, , 3F
10/22 01:03, 3F
→
10/22 01:03, , 4F
10/22 01:03, 4F
推
10/22 01:03, , 5F
10/22 01:03, 5F
→
10/22 01:09, , 6F
10/22 01:09, 6F
推
10/22 10:33, , 7F
10/22 10:33, 7F
→
10/22 10:34, , 8F
10/22 10:34, 8F
→
10/22 10:34, , 9F
10/22 10:34, 9F
→
10/22 10:35, , 10F
10/22 10:35, 10F
→
10/22 10:35, , 11F
10/22 10:35, 11F
→
10/22 16:08, , 12F
10/22 16:08, 12F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章