-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不能打开!n07") ;
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("%sn", xx[i]) ;
fprintf(fp, "%sn", xx[i]) ;
}
fclose(fp) ;
}
字符串处理之九
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不能打开!n07") ;
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("%sn", xx[i]) ;
fprintf(fp, "%sn", 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不能打开!n07") ;
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("%sn", xx[i]) ;
fprintf(fp, "%sn", xx[i]) ;
}
fclose(fp) ;
}