:014:Tình hình thế này các bác àh,tui có làm mấy bài tập xuất nhập file môn cơ sở lập trình 1,không hiểu tại sao khi làm xong nhấn F5 là nó chạy ra thông báo : " Microsost Visual C++ Debug Library Dubug Assertion failed ! Program :\ThucHanhC\taplam\Debug\taplam.exe File: fscanf.c Line :54 Expression : stream != NULL For information on how your program can cause an assertion failure,see the Visual C++ documentation on asserts (Press Retry to debug the application) Abort Retry Ignore " Các bác giúp mình sửa cái lỗi này với,kiểu này chắc lại DIE môn này nữa rồi ,,hichic :simper:
#include<conio.h> #include<stdio.h> #define Fin "nhapmang.inp" #define Fout "xuatmang.out" #define MAX 50 void nhapmang(int &n,int a[MAX]) { FILE *fi; fi=fopen("nhapmang.inp","rt"); fscanf(fi,"%d",&n); for(int i=0;i<n;i++) fscanf(fi,"%d",&a); fclose(fi); } void timphantu(int &n,int &x,int &l,int a[MAX],int b[MAX]) { FILE *f; f=fopen("timpt.inp","rt"); fscanf(f,"%d",&x); int k=0; l=0; for(int i=0;i<n;i++) { if(a==x) { l=l+1; b[k]=i; k++; } } fclose(f); } void xuatmang(int &l,int b[MAX]) { FILE *out; out=fopen("xuatmang.out","wt"); for(int i=0;i<l;i++) fprintf(out,"%3d",b); fclose(out); } void main() { int a[MAX],b[MAX]; int n,x,l; nhapmang(n,a); timphantu(n,x,l,a,b); xuatmang(l,b); } Day la bai tap minh dang lam,chang hieu sao nua //hacgiay: nhắc nhở bạn post bài phải có dấu nhé. đã del nhiều post của bạn rồi không thấy? . tôn trọng rule của 4rum để bạn được hỗ trợ tốt hơn, thân
Thử cái này coi dc ko nha Code: #include<conio.h> #include<stdio.h> #define MAX 50 void nhapmang(int &n,int a[MAX]) { FILE *fi; fi=fopen("nhapmang.inp","rt"); fscanf(fi,"%d",&n); for(int i=0;i<n;i++) fscanf(fi,"%d",&a[i]); fclose(fi); } int timphantu(int n,int x,int a[MAX],int b[MAX]) { FILE *f,*f1; f=fopen("timpt.inp","rt"); fscanf(f,"%d",&x); f1=fopen("nhapmang.inp","rt"); int k=0,l=0; for(int i=0;i<n;i++) { if(a[i]==x) { l=l+1; b[k]=i; k++; } } fclose(f); return l; } void xuatmang(int l,int b[MAX]) { FILE *out; out=fopen("xuatmang.out","wt"); for(int i=0;i<l;i++) fprintf(out,"%3d",b[i]); fclose(out); } void main() { int a[MAX],b[MAX]; int n,x,l; nhapmang(n,a); l=timphantu(n,x,a,b); xuatmang(l,b); }
mình làm nó chạy bình thường mà,lỗi của bạn chắc là do bạn chưa tạo 3 file "nhapmang.inp" "timpt.inp" và "xuatmang.out" đây là project của mình bạn xem thử