[問題] 執行時出錯

看板C_and_CPP (C/C++)作者 (硬漢)時間16年前 (2009/04/30 10:08), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串1/1
#include <stdio.h> #include <stdlib.h> #include <iostream.h> #include <conio.h> void main(void) { FILE *fp_2; int bit,num,out=0; char file_name_2[20]=""; char h_1[15]; printf("file name_2:");//霍夫曼表 scanf("%s",file_name_2); if((fp_2=fopen(file_name_2,"r"))==NULL) { printf("test file name error!!\n"); exit(1); } while(!feof(fp_2)){ fscanf(fp_2,"%d%d%s",bit,num,h_1); cout<<h_1<<endl; } fclose(fp_2); } 我想將一個txt檔讀入,並將其內容一一輸出,我用!feof(fp_2)來判斷是否已全部輸出 完畢,我編譯及link都有過但執行程式時會出現該程式出現問題必需關閉的訊息,我想 請問我的程式到底問題出在哪,請各位大大賜教。 以下是我.txt檔的內容: 0 2 00 1 3 010 2 3 011 3 3 100 4 3 101 5 3 110 6 4 1110 7 5 11110 8 6 111110 9 7 1111110 10 8 11111110 11 9 111111110 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.42.219.246

04/30 10:25, , 1F
int fscanf(FILE* stream, const char* format,...)
04/30 10:25, 1F

04/30 10:26, , 2F
int scanf( const char *format, ... );
04/30 10:26, 2F

04/30 10:28, , 3F
主要是掛在fscanf()
04/30 10:28, 3F

04/30 13:22, , 4F
tnanks a lot^^
04/30 13:22, 4F
文章代碼(AID): #19-GWW0r (C_and_CPP)
文章代碼(AID): #19-GWW0r (C_and_CPP)