Ntxiv Rau Qhov Ntawv Thov Li Cas

Cov txheej txheem:

Ntxiv Rau Qhov Ntawv Thov Li Cas
Ntxiv Rau Qhov Ntawv Thov Li Cas

Video: Ntxiv Rau Qhov Ntawv Thov Li Cas

Video: Ntxiv Rau Qhov Ntawv Thov Li Cas
Video: Yuav ua li cas thiaj thov tau daim ntawv tso cai los qhib business nyob rau lub nroog Minneapolis 2024, Hlis ntuj nqeg
Anonim

Feem ntau thaum lub software khiav, nws yuav tsum nkag mus rau cov ntaub ntawv txuas mus rau hauv ib daim ntawv uas twb muaj lawm. Ntxiv mus, nws yog qhov yuav tsum tau ntxiv cov ntawv nyob rau hauv xws li txoj kev uas tus so ntawm cov ntaub ntawv khaws cia muaj tseem tsis hloov. Txoj haujlwm no tuaj yeem daws tau yooj yim uas siv cov haujlwm ntawm C cov lus sau ua ke. Txoj hauv kev yooj yim rau ntxiv cov ntaub ntawv rau ib qho ntawv yog siv cov cwj pwm tshwj xeeb ntawm cov qauv ua haujlwm. Nrog lawv cov kev pab, koj tuaj yeem qhib thiab ntxiv cov ntaub ntawv rau ib daim ntawv ntau zaus thaum lub sijhawm ua haujlwm.

Ntxiv rau qhov ntawv thov li cas
Ntxiv rau qhov ntawv thov li cas

Tsim nyog

C chaw ib puag ncig

Cov Lus Qhia

Kauj ruam 1

Kev lom zem rau kev ua haujlwm nrog cov ntaub ntawv thiab tawm cov ntaub ntawv rau lawv thaum qhov kev sau C hauv C hauv lub tsev qiv ntawv tshwj xeeb. Txuas rau lawv rau koj qhov program. Txhawm rau ua qhov no, ua ntej sau cov code, qhia kom meej cov ntawv header rau lub tsev qiv ntawv no. Ntaus kab #include "stdio.h".

Kauj ruam 2

Hauv cov ntawv nyeem ntawm cov programme, tsim cov pointer rau cov lus piav qhia. Txhawm rau ua qhov no, sau kab hauv tus txheej txheem code nyiam: FILE * pFile, qhov twg pFile yog lub npe ntawm tus tsim pointer.

Kauj ruam 3

Qhib cov ntaub ntawv uas koj xav tau ntxiv cov ntaub ntawv. Siv cov haujlwm hauv qab no: pFile = fopen ("NameFile.txt", "a"). Ntawm no NameFile.txt yog lub npe ntawm cov ntawv. Qhov ntsuas ob, lub cim ntawm Latin cov tsiaj ntawv, "a" teeb tsa hom kev qhib cov ntawv uas muaj peev xwm ntxiv cov ntaub ntawv rau nws.

Kauj ruam 4

Yog tias cov ntaub ntawv uas koj xav tau ntxiv cov txiaj ntsig tsis nyob hauv cov ntawv qhia koj qhov chaw zov me nyuam ua haujlwm, tom qab ntawd nrog rau cov ntaub ntawv npe sau tag nrho txoj hauv kev rau nws ntawm lub hard disk. Txhawm rau ua qhov no, hloov kab hauv thawj qhov tsis suav. Piv txwv li, txoj hauv kev rau ib daim ntawv nyob hauv cov cag ntoo ntawm D tsav tau teev los ntawm kev nkag mus: "D: NameFile.txt".

Kauj ruam 5

Ntxiv cov ntaub ntawv uas koj xav kom qhib cov ntaub ntawv. Rau qhov no, nws zoo dua yog siv cov haujlwm overloaded fprintf (pFile, Cov ntaub ntawv ntxiv:% s

, datStr). Thawj cov pFile parameter hauv txoj haujlwm no qhia meej cov ntaub ntawv cov ntawv piav qhia yuav tsum tau txuas ntxiv.

Kauj Ruam 6

Cov cim tom qab "%" kos npe qhia cov hom ntawm cov ntaub ntawv tawm. Yog li, qhov qhia "% s" txhais tau tias qhov thib peb parameter ntawm txoj haujlwm yog txoj hlua sib txawv. Txhawm rau tso tawm rau cov ntaub ntawv los ntawm cov sib txawv ntawm hom int, muab cov lus qhia "% d", los tso zis qhov chaw nyob ntawm pointer - "% p". Rau kab noj tom qab cov ntaub ntawv sau cia, lub cim “

. Yog li, cov ntaub ntawv txuas ntxiv nkag mus rau hauv cov ntawv yuav sau rau ntawm kab tshiab.

Kauj Ruam 7

Tom qab muab cov ntaub ntawv koj xav tau, kaw cov ntawv no los ntawm nws txoj kev siv cov fclose (pFile) hais kom ua. Tom qab ntawv khaws cov program, xam thiab khiav nws. Cov ntaub ntawv sau tseg yuav tau ntxiv rau cov ntawv.

Pom zoo: