Help Me !!

Discussion in 'Cafe Wifi' started by hanlephongit, May 15, 2010.

  1. Offline

    hanlephongit

    • Member

    Message Count:
    33
    Likes Received:
    5
    Trophy Points:
    8
    :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 :D:\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:
  2. Offline

    ninomaxx

    • Active Member

    Message Count:
    158
    Likes Received:
    59
    Trophy Points:
    28
    post hết code lên coi thử xem,tui làm xong mấy cái đó ròi,thứ 3 thi gòi T_T
  3. Offline

    HongPhong

    • Member

    Message Count:
    102
    Likes Received:
    1
    Trophy Points:
    18
    stream != NULL

    Đoạn này có phải là câu điều kiện ko ??
  4. Offline

    hanlephongit

    • Member

    Message Count:
    33
    Likes Received:
    5
    Trophy Points:
    8
    #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
  5. Offline

    ninomaxx

    • Active Member

    Message Count:
    158
    Likes Received:
    59
    Trophy Points:
    28
    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);
    }
  6. Offline

    hanlephongit

    • Member

    Message Count:
    33
    Likes Received:
    5
    Trophy Points:
    8
    củng ko chạy được bạn àh
    nó vẫn báo lỗi như lúc đầu mình nói đó
    thật po tay rồi :surrenders:
  7. Offline

    ninomaxx

    • Active Member

    Message Count:
    158
    Likes Received:
    59
    Trophy Points:
    28
    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ử

Share This Page