Yuav Ua Li Cas Los Tso Qhov Tshwm Sim

Cov txheej txheem:

Yuav Ua Li Cas Los Tso Qhov Tshwm Sim
Yuav Ua Li Cas Los Tso Qhov Tshwm Sim

Video: Yuav Ua Li Cas Los Tso Qhov Tshwm Sim

Video: Yuav Ua Li Cas Los Tso Qhov Tshwm Sim
Video: “Yuav Ua Li Cas Zoo Siab Uas Vajtswv Tus Uas Muaj Hwj Chim Loj Kawg Nkaus Tau Los lawm!” 2024, Kaum ib hlis
Anonim

Thaum daws cov teeb meem ntawm lub computer siv hom lus sau, nws yog qhov tsim nyog los nthuav tawm qhov txiaj ntsig ntawm kev daws nyob rau hauv ib daim ntawv kom nkag siab tau rau cov neeg siv. Hauv qhov no, daim foos ntawm kev teeb tsa cov ntaub ntawv tawm tuaj yeem sib txawv. Feem ntau ua tiav ntawm qhov kev zov me nyuam ua haujlwm tau tshwm rau ntawm qhov screen lossis hauv cov ntaub ntawv sab nraud hauv daim ntawv sau. C hom lus ntawm lus Askiv siv cov haujlwm tshwj xeeb los tso saib ntawm lub vijtsam. Nrog lawv cov kev pab, txhua yam ntawm cov ntaub ntawv tuaj yeem muab qhia tau yooj yim ntawm qhov screen lossis hauv cov ntaub ntawv hauv cov sawv cev uas xav tau.

Yuav ua li cas los tso qhov tshwm sim
Yuav ua li cas los tso qhov tshwm sim

Tsim nyog

Ib puag ncig lub cajmeem ntawm C

Cov Lus Qhia

Kauj ruam 1

Txhawm rau siv cov haujlwm uas muab cov txiaj ntsig ntawm cov ntaub ntawv tso tawm, suav nrog lub tsev qiv ntawv tshwj xeeb thaum pib ntawm lub program. Ua qhov no, sau ib kab zoo li: #include.

Kauj ruam 2

Sau qhov program code uas daws cov teeb meem muab tau Yog tias koj siv koj tus kheej lub zog rau kev suav, nco ntsoov xa rov qab txhua qhov nruab nrab ntawm lawv los ntawm txoj haujlwm tseem ceeb. Nws tseem yog qhov xav ua kom pom qhov kawg tshwm sim ntawm qhov screen lossis hauv cov ntaub ntawv los ntawm lub cev tseem ceeb ntawm qhov kev zov me nyuam.

Kauj ruam 3

Siv cov dhau hwv printf muaj nuj nqi los luam tawm qhov tshwm sim rau lub vijtsam. Qhia cov hom tsim tawm tus nqi nrog tus cwj pwm tshwj xeeb hauv ib qho ntawm kev ua haujlwm. Yog tias nce mus nce los nrog zaum kawg tus nqi Qhov tshwm sim ntawm hom int, tom qab ntawd siv cov cim xws li: printf ("

Qhov tshwm sim tau tshwm sim thiab yog sib npaug rau% d

, Cov tshwm sim). Cov lus piav qhia ua ntej qhov sib txawv, sau ib qhov koj xav tau

»Cov khoom lag luam xa khoom xa rov qab, uas yog, tso cai rau koj los muab cov ntaub ntawv tso rau ntawm txoj kab tshiab. Txhawm rau tso tawm qhov sib txawv ntawm cov hlua hom, siv cov cim tshwj xeeb "% s" thiab "% c".

Kauj ruam 4

Qhov tawm ntawm cov txiaj ntsig tshwm sim rau ib daim ntawv tshwm sim siv lwm lub zog. Ua ntej tshaj plaws, qhib cov uas twb muaj lawm lossis tsim cov ntawv tshiab ntawm koj lub hard drive. Txhawm rau ua qhov no, nkag mus rau cov sib txawv hauv qhov program: FILE * fp. Qhib cov ntawv rau sau ntawv: fp = fopen ("output.dat", "w"). Ntawm no output.txt yog lub npe ntawm cov ntawv kom cov txiaj ntsig ntawm qhov tshwm sim, thiab "w" cim qhia kom qhib cov ntaub ntawv hauv hom sau. Yog tias cov ntaub ntawv nrog lub npe no tsis muaj nyob ntawm daim disk, txoj haujlwm yuav tsim nws thaum tua.

Kauj ruam 5

Sau cov tshwm sim tawm mus rau cov ntawv. Ua li no, siv lub fprintf (fp,"

Qhov tshwm sim yog tsim tawm rau ib daim ntawv thiab yog sib npaug%% d

, Tshawb Nrhiav). Thawj qhov ntsuas tau teev cia cov ntaub ntawv piav qhia sau, cov tsis tas yuav zoo sib xws rau cov tau piav qhia rau printf muaj nuj nqi.

Kauj Ruam 6

Tom qab tag nrho cov ntaub ntawv xav tau tshwm sim, kaw cov ntawv nrog fclose (fp) qhov hais kom ua. Tam sim no, thaum koj khiav qhov program, koj yuav pom qhov tshwm sim ntawm qhov screen lossis hauv ib cov ntaub ntawv.

Pom zoo: