黄色在线观看视频-黄色在线免费看-黄色在线视频免费-黄色在线视频免费看-免费啪啪网-免费啪啪网站

網站首頁
分類導航
試題中心
下載中心
英語學習
繽紛校園
考試論壇
網站留言
客服中心
 計算機等級考試三級C語言上機試題總結
【字體:
計算機等級考試三級C語言上機試題總結
http://www.top-99.com.cn 來源:Chinaitlab 點擊: 更新:2005-6-26

英文文章——字符串處理(共10題)之一

code:
/*
函數ReadDat( )實現從文件IN.DAT中讀取一篇英文文章存入到字符串數組xx中; 請編制函數SortCharD( ), 其函數的功能是: 以行為單位對字符按從大到小的順序進行排序, 排序后的結果仍按行重新存入字符串數組xx中。最后main()函數調用函數WriteDat()把結果xx輸出到文件OUT2.DAT中。
例: 原文: dAe,BfC.
CCbbAA
結果: fedCBA.,
bbCCAA
原始數據文件存放的格式是: 每行的寬度均小于80個字符, 含標點符號和空格。

注意: 部分源程序存放在PROG1.C中。
請勿改動主函數main( )、讀數據函數ReadDat()和輸出數據函數WriteDat()的內容。
*/
#include <stdio.h>
#include <string.h>
#include <conio.h>

char xx[50][80] ;
int maxline = 0 ; /* 文章的總行數 */

int ReadDat(void) ;
void WriteDat(void) ;

void SortCharD(void)
{/**/
int i,j,k,m,n; char ch;
for(i=0; i < maxline; i++)
{ j=strlen(xx[i]);
for(m=0; m < j-1; m++)
{ k=m;
for(n=m+1; n < j; n++)
if(xx[i][k] < xx[i][n]) k=n;
if(k!=m)
{ ch=xx[i][k]; xx[i][k]=xx[i][m]; xx[i][m]=ch; }
}
}

/**/
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\n\007") ;
return ;
}
SortCharD() ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen("OUT2.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}


in.dat 文件內容為:
You can create an index on any field, on several fields to be
used
together, or on parts thereof, that you want to use as a key.
The
keys in indexes allow you quick access to specific records and
define
orders for sequential processing of a ISAM file. After you no
longer
need an index, you can delete it. Addition and indexes have no
effect
on the data records or on other indexes.
You may want a field in field in each record to uniquely
identify that
record from all other records in the file. For example, the
Employee
Number field is unique if you do not assign the same number to
two
different employees, and you never reassign these numbers to
other
employees. If you wish to find or modify the record belonging
to a
specific employee, this unique field saves the thouble of
determining
whether you have the correct record.
If you do not have a unique field, you must find the first
record
the matches your key and determine whether the record is the
one you
want. If it is not the correct one, you must search again to
find others.
If you know that you have a unique field within your records,
you
can include this fact in the key description, and ISAM will
allow only
unique keys. For example, if you specify that the employee
numbers are
unique, ISAM only lets you add records to the file for, or
change
numbers to, employee numbers that do not alreadly exist int
file.

out2.dat 文件內容應當為:
yxvuuttsssrroooonnnnnnllliiiffeeeeeeeeeddddccbaaaaaY,
yywuuttttttttsssrrrrpoooooonnkhhhhgfeeeeeeeaaaaaT.,,
yyxwuutssssssrrqpoooonnnnllkkiiiiiiffeeeeeeeeddddccccccaaa
yuuttssssrrrrrrqpooooooonnnnllliiiggffffeeeeeeedcaaSMIAA.
yxxvuttttsooonnnnnnnnliiiiihffeeeeeeeeeeedddddddccaaaaA.,
xtttssrrrrooooonnnihheeeeedddcaa.
yyywuuutttttrrqooonnnnnmllliiiiiiihhfffeeeeeeddddccaaaaaY
yxtttsrrrrrrrppoooooonmmmllllliihhhffeeeeeeeeeeddccaaFE.,
ywuuuuuttttssssrrqooooonnnnmmmliiiiihgffeeeeeeddbbaaN
yyvuuttttsssssrrrrrpoooonnnnnmmliihhgffeeeeeeeeeeeeddbaa,
yyywutttssrrrpoooooooonnnmmlliiiihhggfffeeeeeedddcbaI.
yvuuuttttssssrqppooonnnmmllliiiiiiihhhgfffeeeeeeeeeeeddccba,
ywvutttrrrrrooohhhheeeeeedccca.
yyvuuuuuttttssrrrqooooonnnmliiiihhffffeeeeeddddcaaI,
yyywuuttttttssrrrrroooonnnmmkiihhhhhheeeeeeeeeeeedddccaa
ywuuttttttttssssrrrroooooonnnnnmiiiihhhgffeeeeedcccaaaaI..,
yyyywwvuuuuuutttsrrrqoooooonnnlkiiiihhhffeeeeddcaaaI,
yywwuttttssrpooonnnnnnllllllkiiiiiihhfeeeedddccccaaaaSMIA,
yyyyxuuuutttsssrrrqpppooonnmmmllkiiihhffeeeeeeeeeeecbaaaF.,
yyuuutttssrrrrqoooooonnnllliihhgffeeeeeedddccaaSMIA,,
yyxuuttttttsssrrrpoooonnnnmmmlllliiihfeeeeeeeeddbbaaa.,


字符串處理之二
code:
/*
函數ReadDat( )實現從文件IN.DAT中讀取一篇英文文章存入到字符串數組xx中; 請編制函數ConvertCharA(), 其函數的功能是: 以行為單位把字符串中的所有小寫字母改寫成該字母的下一個字母, 如果是字母z, 則改寫成字母a,大寫字母和其它字符保持不變。把已處理的字符串仍按行重新存入字符串數組xx中。最后main()函數調用函數WriteDat()把結果xx輸出到文件OUT3.DAT中。
例: 原文: Adb.Bcdza
abck.LLhj
結果: Aec.Bdeab
bcdl.LLik
原始數據文件存放的格式是: 每行的寬度均小于80個字符, 含標點符號和空格。

注意: 部分源程序存放在PROG1.C中。
請勿改動主函數main( )、讀數據函數ReadDat()和輸出數據函數WriteDat()的內容。
*/
#include
#include
#include

char xx[50][80] ;
int maxline = 0 ; /* 文章的總行數 */

int ReadDat(void) ;
void WriteDat(void) ;

void ConvertCharA(void)
{/**/
int i,j;
for(i=0; i < maxline; i++)
for(j=0; j < strlen(xx[i]); j++)
if(xx[i][j]=='z') xx[i][j]='a';
else if((xx[i][j]>='a')&&(xx[i][j]<'z')) xx[i][j]++;
/**/
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\n\007") ;
return ;
}
ConvertCharA() ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen("OUT3.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}


out3.dat文件內容應當如下:
Ypv dbo dsfbuf bo joefy po boz gjfme, po tfwfsbm gjfmet up cf
vtfe
uphfuifs, ps po qbsut uifsfpg, uibu zpv xbou up vtf bt b lfz.
Tif
lfzt jo joefyft bmmpx zpv rvjdl bddftt up tqfdjgjd sfdpset boe
efgjof
psefst gps tfrvfoujbm qspdfttjoh pg b ISAM gjmf. Agufs zpv op
mpohfs
offe bo joefy, zpv dbo efmfuf ju. Aeejujpo boe joefyft ibwf op
fggfdu
po uif ebub sfdpset ps po puifs joefyft.
Ypv nbz xbou b gjfme jo gjfme jo fbdi sfdpse up vojrvfmz
jefoujgz uibu
sfdpse gspn bmm puifs sfdpset jo uif gjmf. Fps fybnqmf, uif
Enqmpzff
Nvncfs gjfme jt vojrvf jg zpv ep opu bttjho uif tbnf ovncfs up
uxp
ejggfsfou fnqmpzfft, boe zpv ofwfs sfbttjho uiftf ovncfst up
puifs
fnqmpzfft. Ig zpv xjti up gjoe ps npejgz uif sfdpse cfmpohjoh
up b
tqfdjgjd fnqmpzff, uijt vojrvf gjfme tbwft uif uipvcmf pg
efufsnjojoh
xifuifs zpv ibwf uif dpssfdu sfdpse.
Ig zpv ep opu ibwf b vojrvf gjfme, zpv nvtu gjoe uif gjstu
sfdpse
uif nbudift zpvs lfz boe efufsnjof xifuifs uif sfdpse jt uif
pof zpv
xbou. Ig ju jt opu uif dpssfdu pof, zpv nvtu tfbsdi bhbjo up
gjoe puifst.
Ig zpv lopx uibu zpv ibwf b vojrvf gjfme xjuijo zpvs sfdpset,
zpv
dbo jodmvef uijt gbdu jo uif lfz eftdsjqujpo, boe ISAM xjmm
bmmpx pomz
vojrvf lfzt. Fps fybnqmf, jg zpv tqfdjgz uibu uif fnqmpzff
ovncfst bsf
vojrvf, ISAM pomz mfut zpv bee sfdpset up uif gjmf gps, ps
dibohf
ovncfst up, fnqmpzff ovncfst uibu ep opu bmsfbemz fyjtu jou
gjmf.

字符串處理之三
code:
/*
函數ReadDat( )實現從文件IN.DAT中讀取一篇英文文章存入到字符串數組xx中; 請編制函數SortCharA( ), 其函數的功能是: 以行為單位對字符按從小到大的順序進行排序, 排序后的結果仍按行重新存入字符串數組xx中。最后main()函數調用函數WriteDat()把結果xx輸出到文件OUT1.DAT中。
例: 原文: dAe,BfC.
CCbbAA
結果: ,.ABCdef
AACCbb
原始數據文件存放的格式是: 每行的寬度均小于80個字符, 含標點符號和空格。

注意: 部分源程序存放在PROG1.C中。
請勿改動主函數main( )、讀數據函數ReadDat()和輸出數據函數WriteDat()的內容。
*/
#include
#include
#include

char xx[50][80] ;
int maxline = 0 ; /* 文章的總行數 */

int ReadDat(void) ;
void WriteDat(void) ;

void SortCharA(void)
{/**/
int i,j,k,m,n; char ch;
for(i=0; i < maxline; i++)
{ j=strlen(xx[i]);
for(m=0; m < j-1; m++)
{ k=m;
for(n=m+1; n < j; n++)
if(xx[i][k] > xx[i][n]) k=n;
if(k!=m)
{ ch=xx[i][k]; xx[i][k]=xx[i][m]; xx[i][m]=ch; }
}
}
/**/
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\n\007") ;
return ;
}
SortCharA() ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen("OUT1.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}

out1.dat 文件內容如下(注意每行的前面有若干空格):
,Yaaaaabccddddeeeeeeeeeffiiilllnnnnnnoooorrsssttuuvxy
,,.Taaaaaeeeeeeefghhhhknnooooooprrrrsssttttttttuuwyy
aaaccccccddddeeeeeeeeffiiiiiikkllnnnnoooopqrrsssssstuuwxyy
.AAIMSaacdeeeeeeeffffggiiilllnnnnooooooopqrrrrrrssssttuuy
,.Aaaaaccdddddddeeeeeeeeeeeffhiiiiilnnnnnnnnooosttttuvxxy
.aacdddeeeeehhinnnooooorrrrsstttx
Yaaaaaccddddeeeeeefffhhiiiiiiilllmnnnnnoooqrrtttttuuuwyyy
,.EFaaccddeeeeeeeeeeffhhhiilllllmmmnoooooopprrrrrrrstttxy
Naabbddeeeeeeffghiiiiilmmmnnnnoooooqrrssssttttuuuuuwy
,aabddeeeeeeeeeeeeffghhiilmmnnnnnooooprrrrrsssssttttuuvyy
.Iabcdddeeeeeefffgghhiiiillmmnnnooooooooprrrsstttuwyyy
,abccddeeeeeeeeeeefffghhhiiiiiiilllmmnnnoooppqrssssttttuuuvy
.acccdeeeeeehhhhooorrrrrtttuvwy
,Iaacddddeeeeeffffhhiiiilmnnnoooooqrrrssttttuuuuuvyy
aaccdddeeeeeeeeeeeehhhhhhiikmmnnnoooorrrrrssttttttuuwyyy
,..Iaaaacccdeeeeeffghhhiiiimnnnnnoooooorrrrssssttttttttuuwy
,Iaaacddeeeeffhhhiiiiklnnnooooooqrrrstttuuuuuuvwwyyyy
,AIMSaaaaccccdddeeeefhhiiiiiikllllllnnnnnnoooprssttttuwwyy
,.Faaabceeeeeeeeeeeffhhiiikllmmmnnooopppqrrrssstttuuuuxyyyy
,,AIMSaaccdddeeeeeeffghhiilllnnnooooooqrrrrsstttuuuyy
,.aaabbddeeeeeeeefhiiillllmmmnnnnooooprrrsssttttttuuxyy

字符串處理之四
code:
/*
函數ReadDat( )實現從文件IN.DAT中讀取一篇英文文章存入到字符串數組xx中; 請編制函數StrCharJL( ), 其函數的功能是: 以行為單位把字符串中的所有字符的ASCII值左移4位, 如果左移后,其字符的ASCII值小于等于32或大于100, 則原字符保持不變, 否則就把左移后的字符ASCII值再加上原字符的ASCII值, 得到新的字符仍存入原字符串對應的位置上,之后把已處理的字符串仍按行重新存入字符串數組xx中。最后main()函數調用函數WriteDat()把結果xx輸出到OUT7.DAT文件中。
原始數據文件存放的格式是: 每行的寬度均小于80個字符, 含標點符號和空格。

注意: 部分源程序存放在PROG1.C中。
請勿改動主函數main( )、讀數據函數ReadDat()和輸出數據函數WriteDat()的內容。
*/
#include
#include
#include

char xx[50][80] ;
int maxline = 0 ; /* 文章的總行數 */

int ReadDat(void) ;
void WriteDat(void) ;

void StrCharJL(void)
{/**/
int i,j; char m;
/****老王注:此題的關鍵是定義 char m 。記得往年的考試類似題可以不必定義,如果要定義的話,則必須定義為 int 結果才能正確?磥砝斫獬鲱}者的意圖是機試的難點之一。 ****/
for(i=0; i < maxline; i++)
for(j=0; j < strlen(xx[i]); j++)
{ m=xx[i][j]<<4;
if((m>32)&&(m<=100))
xx[i][j]+=m;
}
/**/
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\n\007") ;
return ;
}
StrCharJL() ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen("OUT7.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}

字符串處理之五
code:
/*
函數ReadDat( )實現從文件IN.DAT中讀取一篇英文文章存入到字符串數組xx中; 請編制函數StrCharJR( ), 其函數的功能是: 以行為單位把字符串中的所有字符的ASCII值右移4位, 然后把右移后的字符ASCII值再加上原字符的ASCII值, 得到新的字符仍存入原字符串對應的位置上,之后把已處理的字符串仍按行重新存入字符串數組xx中。最后main()函數調用函數WriteDat()把結果xx輸出到文件OUT8.DAT中。
原始數據文件存放的格式是: 每行的寬度均小于80個字符, 含標點符號和空格。

注意: 部分源程序存放在PROG1.C中。
請勿改動主函數main( )、讀數據函數ReadDat()和輸出數據函數WriteDat()的內容。
*/
#include
#include
#include

char xx[50][80] ;
int maxline = 0 ; /* 文章的總行數 */

int ReadDat(void) ;
void WriteDat(void) ;

void StrCharJR(void)
{/**/
int i,j;
for(i=0; i
for(j=0; j
xx[i][j]+=xx[i][j]>>4;
/**/
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\n\007") ;
return ;
}
StrCharJR() ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen("OUT8.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}

out8.dat 文件內容應當如下:
^u|"igt"iykg{k"gt"otjk"ut"gt"lokrj."ut"zk}kygr"lokrjz"{u"hk"|zkj

{umk{nky."uy"ut"wgy{z"{nkykul."{ng{"u|"~gt{"{u"|zk"gz"g"qk0"Ynk

qkz"ot"otjkkz"grru~"u|"x|oiq"giikzz"{u"zwkioloi"ykiuyjz"gtj"jklotk

uyjkyz"luy"zkx|kt{ogr"wyuikzzotm"ul"g"MXEQ"lork0"El{ky"u|"tu"rutmky

tkkj"gt"otjk."u|"igt"jkrk{k"o{0"Ejjo{out"gtj"otjkkz"ng}k"tu"kllki{

ut"{nk"jg{g"ykiuyjz"uy"ut"u{nky"otjkkz0
^u|"sg"~gt{"g"lokrj"ot"lokrj"ot"kgin"ykiuyj"{u"|tox|kr"ojkt{ol"{ng{

ykiuyj"lyus"grr"u{nky"ykiuyjz"ot"{nk"lork0"Juy"kgswrk."{nk"Iswrukk

R|shky"lokrj"oz"|tox|k"ol"u|"ju"tu{"gzzomt"{nk"zgsk"t|shky"{u"{~u

jollkykt{"kswrukkz."gtj"u|"tk}ky"ykgzzomt"{nkzk"t|shkyz"{u"u{nky

kswrukkz0"Ml"u|"~ozn"{u"lotj"uy"sujol"{nk"ykiuyj"hkrutmotm"{u"g

zwkioloi"kswrukk."{noz"|tox|k"lokrj"zg}kz"{nk"{nu|hrk"ul"jk{kysototm

~nk{nky"u|"ng}k"{nk"iuyyki{"ykiuyj0
Ml"u|"ju"tu{"ng}k"g"|tox|k"lokrj."u|"s|z{"lotj"{nk"loyz{"ykiuyj

{nk"sg{inkz"u|y"qk"gtj"jk{kysotk"~nk{nky"{nk"ykiuyj"oz"{nk"utk"u|

~gt{0"Ml"o{"oz"tu{"{nk"iuyyki{"utk."u|"s|z{"zkgyin"gmgot"{u"lotj"u{nkyz0

Ml"u|"qtu~"{ng{"u|"ng}k"g"|tox|k"lokrj"~o{not"u|y"ykiuyjz."u|

igt"otir|jk"{noz"lgi{"ot"{nk"qk"jkziyow{out."gtj"MXEQ"~orr"grru~"utr

|tox|k"qkz0"Juy"kgswrk."ol"u|"zwkiol"{ng{"{nk"kswrukk"t|shkyz"gyk

|tox|k."MXEQ"utr"rk{z"u|"gjj"ykiuyjz"{u"{nk"lork"luy."uy"ingtmk

t|shkyz"{u."kswrukk"t|shkyz"{ng{"ju"tu{"grykgjr"koz{"ot{"lork0


字符串處理之六
code:
/*
函數ReadDat( )實現從文件IN.DAT中讀取一篇英文文章存入到字符串數組xx中; 請編制函數StrOL( ), 其函數的功能是: 以行為單位對行中以空格或標點符號為分隔的所有單詞進行倒排,同時去除標點符號,之后把已處理的字符串(應不含標點符號)仍按行重新存入字符串數組xx中。最后main()函數調用函數WriteDat()把結果xx輸出到文件OUT6.DAT中。
例如: 原文: You He Me
I am a student.
結果: Me He You
student a am I
原始數據文件存放的格式是: 每行的寬度均小于80個字符, 含標點符號和空格。

注意: 部分源程序存放在PROG1.C中。
請勿改動主函數main( )、讀數據函數ReadDat()和輸出數據函數WriteDat()的內容。

**** 同1998年3B第六題 ****
*/
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>

char xx[50][80] ;
int maxline = 0 ; /* 文章的總行數 */

int ReadDat(void) ;
void WriteDat(void) ;

void StrOL(void)
{/**/
int i,j,k,m,n,ll;
char yy[80];
for(i=0; i < maxline; i++)
{ ll=strlen(xx[i]); k=n=0;
for(j=ll-1; j>=0; j--)
{ if(isalpha(xx[i][j])) k++;
else
{ for(m=1; m<=k; m++)
yy[n++]=xx[i][j+m];
k=0;
}
if(xx[i][j]==' ') yy[n++]=' ';
}
for(m=1; m<=k; m++)
yy[n++]=xx[i][j+m];
/* 上面兩行處理每行的第一個單詞。
如果漏寫,結果顯然不正確,但并不影響得分。 */
yy[n]=0;
strcpy(xx[i],yy);
}
/* 標準答案與此法結果相比,每行后面多一個空格。 */
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\n\007") ;
return ;
}
StrOL() ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen("OUT6.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}

out6.dat 內容應當如下:
used be to fields several on field any on index an create can
You
The key a as use to want you that thereof parts on or together

define and records specific to access quick you allow indexes
in keys
longer no you After file ISAM a of processing sequential for
orders
effect no have indexes and Addition it delete can you index an
need
indexes other on or records data the on
that identify uniquely to record each in field in field a want
may You
Employee the example For file the in records other all from
record
two to number same the assign not do you if unique is field
Number
other to numbers these reassign never you and employees
different
a to belonging record the modify or find to wish you If
employees
determining of thouble the saves field unique this employee
specific
record correct the have you whether
record first the find must you field unique a have not do you
If
you one the is record the whether determine and key your
matches the
others find to again search must you one correct the not is it
If want
you records your within field unique a have you that know you
If
only allow will ISAM and description key the in fact this
include can
are numbers employee the that specify you if example For keys
unique
change or for file the to records add you lets only ISAM
unique
file int exist alreadly not do that numbers employee to
numbers

字符串處理之七
code:
/*
函數ReadDat( )實現從文件IN.DAT中讀取一篇英文文章存入到字符串數組xx中; 請編制函數ConvertCharD(), 其函數的功能是: 以行為單位把字符串中的所有小寫字母改寫成該字母的上一個字母, 如果是字母a, 則改寫成字母z,大寫字母和其它字符保持不變。把已處理的字符串仍按行重新存入字符串數組xx中。最后main()函數調用函數WriteDat()把結果xx輸出到文件OUT4.DAT中。
例: 原文: Adb.Bcdza
abck.LLhj
結果: Aca.Bbcyz
zabj.LLgi
原始數據文件存放的格式是: 每行的寬度均小于80個字符, 含標點符號和空格。

注意: 部分源程序存放在PROG1.C中。
請勿改動主函數main( )、讀數據函數ReadDat()和輸出數據函數WriteDat()的內容。
*/
#include <stdio.h>
#include <string.h>
#include <conio.h>

char xx[50][80] ;
int maxline = 0 ; /* 文章的總行數 */

int ReadDat(void) ;
void WriteDat(void) ;

void ConvertCharD(void)
{/**/
int i,j;
for(i=0; i < maxline; i++)
for(j=0; j < strlen(xx[i]); j++)
if(xx[i][j]=='a') xx[i][j]='z';
else if(islower(xx[i][j])) xx[i][j]-=1;
/**/
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\n\007") ;
return ;
}
ConvertCharD() ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen("OUT4.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}

out4.dat 文件內容應當如下:
Ynt bzm bqdzsd zm hmcdw nm zmx ehdkc, nm rdudqzk ehdkcr sn ad
trdc
snfdsgdq, nq nm ozqsr sgdqdne, sgzs xnt vzms sn trd zr z jdx.
Tgd
jdxr hm hmcdwdr zkknv xnt pthbj zbbdrr sn rodbhehb qdbnqcr zmc
cdehmd
nqcdqr enq rdptdmshzk oqnbdrrhmf ne z ISAM ehkd. Aesdq xnt mn
knmfdq
mddc zm hmcdw, xnt bzm cdkdsd hs. Acchshnm zmc hmcdwdr gzud mn
deedbs
nm sgd czsz qdbnqcr nq nm nsgdq hmcdwdr.
Ynt lzx vzms z ehdkc hm ehdkc hm dzbg qdbnqc sn tmhptdkx
hcdmshex sgzs
qdbnqc eqnl zkk nsgdq qdbnqcr hm sgd ehkd. Fnq dwzlokd, sgd
Eloknxdd
Ntladq ehdkc hr tmhptd he xnt cn mns zrrhfm sgd rzld mtladq sn
svn
cheedqdms dloknxddr, zmc xnt mdudq qdzrrhfm sgdrd mtladqr sn
nsgdq
dloknxddr. Ie xnt vhrg sn ehmc nq lnchex sgd qdbnqc adknmfhmf
sn z
rodbhehb dloknxdd, sghr tmhptd ehdkc rzudr sgd sgntakd ne
cdsdqlhmhmf
vgdsgdq xnt gzud sgd bnqqdbs qdbnqc.
Ie xnt cn mns gzud z tmhptd ehdkc, xnt ltrs ehmc sgd ehqrs
qdbnqc
sgd lzsbgdr xntq jdx zmc cdsdqlhmd vgdsgdq sgd qdbnqc hr sgd
nmd xnt
vzms. Ie hs hr mns sgd bnqqdbs nmd, xnt ltrs rdzqbg zfzhm sn
ehmc nsgdqr.
Ie xnt jmnv sgzs xnt gzud z tmhptd ehdkc vhsghm xntq qdbnqcr,
xnt
bzm hmbktcd sghr ezbs hm sgd jdx cdrbqhoshnm, zmc ISAM vhkk
zkknv nmkx
tmhptd jdxr. Fnq dwzlokd, he xnt rodbhex sgzs sgd dloknxdd
mtladqr zqd
tmhptd, ISAM nmkx kdsr xnt zcc qdbnqcr sn sgd ehkd enq, nq
bgzmfd
mtladqr sn, dloknxdd mtladqr sgzs cn mns zkqdzckx dwhrs hms
ehkd.

字符串處理之八
code:
/*
函數ReadDat( )實現從文件IN.DAT中讀取一篇英文文章存入到字符串數組xx中; 請編制函數CharConvA( ), 其函數的功能是: 以行為單位把字符串中的最后一個字符的ASCII值右移4位后加最后第二個字符的ASCII值, 得到最后一個新的字符, 最后第二個字符的ASCII值右移4位后加最后第三個字符的ASCII值,得到最后第二個新的字符, 以此類推一直處理到第二個字符, 第一個字符的ASCII值加原最后一個字符的ASCII值, 得到第一個新的字符, 得到的新字符分別存放在原字符串對應的位置上,之后把已處理的字符串仍按行重新存入字符串數組xx中。最后main()函數調用函數WriteDat()把結果xx輸出到文件OUT10.DAT中。

原始數據文件存放的格式是: 每行的寬度均小于80個字符, 含標點符號和空格。

注意: 部分源程序存放在PROG1.C中。
請勿改動主函數main( )、讀數據函數ReadDat()和輸出數據函數WriteDat()的內容。
*/
#include <stdio.h>
#include <string.h>
#include <conio.h>

char xx[50][80] ;
int maxline = 0 ; /* 文章的總行數 */

int ReadDat(void) ;
void WriteDat(void) ;

void CharConvA(void)
{/**/
int i,j,ll; char ch;
for(i=0; i < maxline; i++)
{ ll=strlen(xx[i]); ch=xx[i][ll-1];
for(j=ll-1; j; j--)
xx[i][j]=(xx[i][j]>>4)+xx[i][j-1];
xx[i][0]+=ch;
}
/**/
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\n\007") ;
return ;
}
CharConvA() ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen("OUT10.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}

字符串處理之9
code:
/*
函數ReadDat( )實現從文件IN.DAT中讀取一篇英文文章存入到字符串數組xx中; 請編制函數StrOR( ), 其函數的功能是: 以行為單位依次把字符串中所有小寫字母o 左邊的字符串內容移到該串的右邊存放, 然后并把小寫字母o刪除,余下的字符串內容移到已處理字符串的左邊存放,之后把已處理的字符串仍按行重新存入字符串數組xx中。最后main()函數調用函數WriteDat()把結果xx輸出到文件OUT5.DAT中。
例如: 原文: You can create an index on any field.
you have the correct record.
結果: n any field. Yu can create an index
rd. yu have the crrect rec
原始數據文件存放的格式是: 每行的寬度均小于80個字符, 含標點符號和空格。

注意: 部分源程序存放在PROG1.C中。
請勿改動主函數main( )、讀數據函數ReadDat()和輸出數據函數WriteDat()的內容。

*/
#include <stdio.h>
#include <string.h>
#include <conio.h>

char xx[50][80] ;
int maxline = 0 ; /* 文章的總行數 */

int ReadDat(void) ;
void WriteDat(void) ;

void StrOR(void)
{/**/
int i,j; char yy[80],*p;
for(i=0; i
for(j=0; j
if(xx[i][j]=='o')
{ p=&xx[i][j+1];
strcpy(yy,p);
strncat(yy,xx[i],j);
strcpy(xx[i],yy);
j=0;
}
/**/
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\n\007") ;
return ;
}
StrOR() ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen("OUT5.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}

out5.dat 文件內容應當如下:

be usedYu can create an index n any field, n several fields t
use as a key. Thetgether, r n parts theref, that yu want t
rds and definekeys in indexes allw yu quick access t specific
rec
ngerrders fr sequential prcessing f a ISAM file. After yu n l
effectneed an index, yu can delete it. Additin and indexes
have n
ther indexes.n the data recrds r n
uniquely identify thatYu may want a field in field in each
recrd t
yeerecrd frm all ther recrds in the file. Fr example, the Empl

Number field is unique if yu d nt assign the same number t tw
therdifferent emplyees, and yu never reassign these numbers t
aemplyees. If yu wish t find r mdify the recrd belnging t
f determiningspecific emplyee, this unique field saves the
thuble
rd.whether yu have the crrect rec
rdIf yu d nt have a unique field, yu must find the first rec
uthe matches yur key and determine whether the recrd is the ne
y
thers.want. If it is nt the crrect ne, yu must search again t
find
uIf yu knw that yu have a unique field within yur recrds, y
nlycan include this fact in the key descriptin, and ISAM will
allw
yee numbers areunique keys. Fr example, if yu specify that the
empl
r changeunique, ISAM nly lets yu add recrds t the file fr,
t alreadly exist int file.numbers t, emplyee numbers that d n

字符串處理之10
code:
/*
函數ReadDat( )實現從文件IN.DAT中讀取一篇英文文章存入到字符串數組xx中; 請編制函數ChA( ), 其函數的功能是: 以行為單位把字符串中的第一個字符的ASCII值加第二個字符的ASCII值, 得到第一個新的字符, 第二個字符的ASCII值加第三個字符的ASCII值,得到第二個新的字符, 以此類推一直處理到最后第二個字符, 最后一個字符的ASCII值加原第一個字符的ASCII值, 得到最后一個新的字符, 得到的新字符分別存放在原字符串對應的位置上,之后把已處理的字符串逆轉后仍按行重新存入字符串數組xx中。最后main()函數調用函數WriteDat()把結果xx輸出到文件OUT9.DAT中。原始數據文件存放的格式是: 每行的寬度均小于80個字符, 含標點符號和空格。

注意: 部分源程序存放在PROG1.C中。
請勿改動主函數main( )、讀數據函數ReadDat()和輸出數據函數WriteDat()的內容。
*/
#include <stdio.h>
#include <string.h>
#include <conio.h>

char xx[50][80] ;
int maxline = 0 ; /* 文章的總行數 */

int ReadDat(void) ;
void WriteDat(void) ;

void ChA(void)
{/**/
int i,j; char ch;
for(i=0; i < maxline; i++)
{ ch=xx[i][0];
for(j=0; j < strlen(xx[i])-1; j++)
xx[i][j]+=xx[i][j+1];
xx[i][j]+=ch;
strrev(xx[i]);
}
/**/
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\n\007") ;
return ;
}
ChA() ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen("OUT9.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}

上一頁  [1] [2] 

文章錄入:ak47    責任編輯:ak47  
 版權聲明
   如果本網站所轉載內容不慎侵犯了您的權益,請與我們聯系,我們將會及時處理。如轉載本網內容,請注明出處。
 發表評論
關于本站 網站聲明 廣告服務  聯系方式  付款方式  站內導航  客服中心  友情鏈接   
Copyright © 2004-2006 考試吧 (Exam8.com) All Rights Reserved 
中國科學院研究生院中關村園區(北京市海淀區)
主站蜘蛛池模板: 中文字幕手机在线播放 | 亚洲国产欧美久久香综合 | 影音先锋国产资源 | 欧美国产日韩精品 | 成人网在线观看 | 国产日产亚洲欧美综合另类 | 亚洲精品乱码国产精品乱码 | 99r在线视频 | 一级特黄高清完整大片 | 欧美一级免费观看 | 最近更新2019中文字幕 | 人成在线免费视频 | 国产在线精品二区李沁 | www.九色视频 | 91视频最新地址 | xxxx日本69xxxxx| 天天做天天爱天天一爽一毛片 | 福利影院在线播放 | www.日韩三级 | 欧美日韩资源 | www污视频 | 免费级毛片| 日韩免费精品一级毛片 | 精品国产一区二区三区香蕉 | 久久天天躁夜夜躁狠狠躁2020 | 黄色在线观看视频 | 香港三级日本三级人妇网站 | 成人精品免费网站 | 无夜精品久久久久久 | www视频在线免费观看 | 黄色激情网址 | 亚洲视频在线观看免费视频 | 日本天堂免费观看 | m乳娘调教人h | 色欧美片视频在线观看 | 亚洲激情在线视频 | 一区二区三区午夜 | 美国一级毛片免费看成人 | 亚洲欧美日韩国产精品26u | 你懂的手机在线 | 伦理在线 |