Bai 3 - Tong Quan Ve Xu Ly File

  • Published on
    30-May-2018

  • View
    217

  • Download
    0

Embed Size (px)

Transcript

  • 8/9/2019 Bai 3 - Tong Quan Ve Xu Ly File

    1/2

    Nguyn Tri Tun Khoa CNTT, H.KHTN, TP.HCM 1/2

    Data Structure & Algorithm

    Tng quan v xl file(Phn tnghin cu)

    ---oOo---

    I. Mc tiu- Hiu v thc hin c cc thao tc cbn trn tp tin, s dng C/C++- Chun b cc k nng thc hnh cbn cho nhng chng tip theo ca mn hc CTDL2

    II. Thi gian- Thi gian tm hiu v ci t bi tp: 1 tun

    III.Ni dung1. Gii thiu

    - Tp tin l g ?- Cch thc lu tr tp tin trn a: mc logic ? mc vt l ?

    2. S khc bit cbn gia tp tin v mng3. Nguyn tc cbn khi x l trn file

    - Mfile- Truy xut: c, ghi, dch chuyn u c file- ng file

    4. Cc thao tc x l cbn trn file trong C/C++- Truy xut file vi ch text: M(fopen), ng (fclose), c phn t (fscanf, fgetc,

    fgets), ghi phn t (fprintf, fputc, fputs), kim tra cui file (feof)- Truy xut file vi ch nh phn (binary): M(fopen), ng (fclose), c phn t

    (fread, fgetc), ghi phn t (fwrite, fputc), dch chuyn u c file (fseek), xc nh v

    tru c file (ftell), kim tra cui file (feof)5. Vng m truy xut file (Buffer)

    - Buffer l gi ?- Cng dng ca Buffer- Cc thao tc trn buffer trong C/C++: thay i kch thc buffer khi truy xut file

    (setbuf), lm sch buffer (fflush, flushall)

    IV.Bi tp1. Cho 1 tp tin dng text mang tn STRINGS.TXT

    Hy vit chng trnh c v hin th ni dung tp tin ln mn hnh2. Cho 1 tp tin dng text mang tn NUMBERS.TXT

    Hy vit chng trnh c v hin th ni dung tp tin ln mn hnh3. Cho 1 tp tin dng text mang tn ODBCINST.INI

    Hy vit chng trnh c v hin th ln mn hnh:- tn file driver dng cho kt ni ODBC ca Oracle (c xc nh trong mc

    Driver ca phn Microsoft ODBC for Oracle (32 bit))- tn file driver dng cho kt ni ODBC ca SQL Server (c xc nh trong mc

    Driver ca phn SQL Server (32 bit))

  • 8/9/2019 Bai 3 - Tong Quan Ve Xu Ly File

    2/2

    Nguyn Tri Tun Khoa CNTT, H.KHTN, TP.HCM 2/2

    4. Cho 2 tp tin dng text mang tn NUMBER1.TXT v NUMBER2.TXT. Bit rng gi trcc s trong mi tp tin c th t tng dnHy vit chng trnh to 1 file text mi c tn NUMBER12.TXT c ni dung tng hpt 2 file trn v sp theo t t tng dn

    5. Cho 1 tp tin dng text mang tn README.TXTHy vit chng trnh c v thng k s ln xut hin ca mi loi k t trong file nitrn. Phn bit ch thng v ch hoa. Kt qu thng k ghi ra 1 file text c tnTHONGKE.TXT theo mu sau

    So loai ky tu = xxx

    a =

    b =

    c =

    d =

    6. Cho 1 tp tin dng binary mang tn NUMBERS.BIN, mi phn t trong file l 1 snguyn (int 2 bytes). Hy vit chng trnh c v tnh tng gi tr cc phn t trong file

    trn7. Hy to 1 file dng binary cha cc s nguyn vi d liu ly t file NUMBERS.TXT8. Hy to 1 file dng binary cha cc s nguyn theo th t ngc li vi d liu trong file

    NUMBERS.BIN

    9. Vit chng trnh xa 1 s nguyn cho trc trong file NUMBERS.BIN. Chng trnhthi hnh theo c php dng lnh nh sau:

    C:\>Bai9 X

    Trong : X l gi tr cn xa10.Vit chng trnh chn 1 s nguyn cho trc vo sau 1 gi tr xc nh trong file

    NUMBERS.BIN. Chng trnh thi hnh theo c php dng lnh nh sau:C:\>Bai10 X Y

    Trong :- X l gi tr cn chn vo file. X sc chn vo sau gi tr Y. Nu Y khng tn

    ti th X c thm vo cui file

    --- Ht ---