[問題] Queue讀入資料
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
想請教一下為什麼我show出來的結果皆為0
餵入的資料(Input):
預期的正確結果(Expected Output):
將materials.txt的資料讀進QUEUE
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
int _tmain(int argc, _TCHAR* argv[])
{
FILE* f1;
fopen_s(&f1,"materials.txt","r");
char x;
createq();
while(fscanf_s(f1,"%c",&x)!=EOF)
{
addq(x);
}
fclose(f1);
showqueue();
system("pause");
return 0;
}
void createq(){
rear=front=(Node*)malloc(sizeof(Node));
front->next=rear->next=NULL;
}
void addq(char x){
Node* newnode;
newnode = (Node*) malloc(sizeof(Node));
if(front->next == NULL)
front->next = newnode;
newnode->data = x;
newnode->next = NULL;
rear->next = newnode;
rear = newnode;
}
void showqueue() {
Node* tmpnode;
tmpnode = front->next;
printf("\n佇列內容:");
while(tmpnode != NULL) {
printf("%d ", tmpnode->data);
tmpnode = tmpnode->next;
}
}
補充說明(Supplement):
麻煩各位大大指點迷津了,感恩!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.114.212.113
→
11/13 15:14, , 1F
11/13 15:14, 1F
→
11/13 17:35, , 2F
11/13 17:35, 2F
推
11/14 19:53, , 3F
11/14 19:53, 3F
推
11/15 17:52, , 4F
11/15 17:52, 4F
→
11/15 17:53, , 5F
11/15 17:53, 5F
→
11/15 17:53, , 6F
11/15 17:53, 6F
→
11/15 17:54, , 7F
11/15 17:54, 7F