英文文章——字符串处理(共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
#include
#include
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]
/**/
}
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"qk�0"Ynk
qk�z"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"Iswru�kk
R|shky"lokrj"oz"|tox|k"ol"�u|"ju"tu{"gzzomt"{nk"zgsk"t|shky"{u"{~u
jollkykt{"kswru�kkz."gtj"�u|"tk}ky"ykgzzomt"{nkzk"t|shkyz"{u"u{nky
kswru�kkz0"Ml"�u|"~ozn"{u"lotj"uy"sujol�"{nk"ykiuyj"hkrutmotm"{u"g
zwkioloi"kswru�kk."{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"qk�z0"Juy"kgswrk."ol"�u|"zwkiol�"{ng{"{nk"kswru�kk"t|shkyz"gyk
|tox|k."MXEQ"utr�"rk{z"�u|"gjj"ykiuyjz"{u"{nk"lork"luy."uy"ingtmk
t|shkyz"{u."kswru�kk"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
#include
#include
#include
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
#include
#include
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
#include
#include
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
#include
#include
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
#include
#include
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) ;
}