★题目100(无忧id 21字符替换题)
函数ReadDat()实现从文件IN.DAT中读取一篇英文文章存入到字符串数组xx中,请编制函数CharConvA(),其函数的功能是:以行为单位把字符串中的最后一个字符的ASCII值右移4位后加最后第二个字符的ASCII值,得到最后一个新的字符,最后第二个字符的ASCII值右移4位后加最后第三个字符的ASCII值,得到最后第二个新的字符,依此类推一直处理到第二个字符,第一个字符的ASCII值加原最后一个字符的ASCII值,得到第一个新的字符,得到的新字符分别存放在原字符串对应的位置上。最后已处理的字符串仍按行重新存入字符串数组xx中,最后调用函数writeDat()把结果xx输出到文件OUT10.DAT中。
原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格。
部分源程序存在文件prog1.c中。
请勿改动主函数main()和写函数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()
{ int i,j;
char p,c;
for(i=0;i<maxline;i++)
{ p=xx[i][strlen(xx[i])-1];
c=xx[i][0];
for(j=strlen(xx[i])-1;j>0;j--)
xx[i][j]=(xx[i][j]>>4)+xx[i][j-1];
xx[i][0]=p+c;
}
}
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;
fp=fopen("OUT10.DAT","w");
for(i=0;i<maxline;i++){
printf("%s\n",xx[i]);
fprintf(fp,"%s\n",xx[i]);
}
fclose(fp);
}
新题补充:
函数ReadDat()实现从文件ENG.IN中读取一篇英文文章存入到字符串数组xx中;请编制函数DelWord()分别按行删除空格、标点符号等非字符,并对每行的单词按升序排好序后存放回数组XX中,最后调用
函数WriteDat()把结果xx输出到文件PS6.OUT中。
原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格。
注意:部分源程序存放在文件prog1.c中。文章每行中的单词与单词之间用空格或其它标点符号分隔,每单词均小于20个字符。
请勿改动主函数main()、读数据函数ReadDat()和输出数据函数WriteDat()的内容。
#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 DelWord(void)
{ int i,j,k,m,cnt;
char *p, word[20],str[80][20],abc[80];
for(i=0;i<maxline;i++)
{ memset(word,0,20);
memset(str,0,80);
memset(abc,0,80);
k=cnt=0;
p=xx[i];
while(*p)
{ while(isalpha(*p)) word[k++]=*p++;
if(strlen(word)) strcpy(str[cnt++],word);
memset(word,0,20);
k=0;
while(!isalpha(*p)&&*p) p++;
}
for(j=0;j<cnt-1;j++)
for(m=j+1;m<cnt;m++)
if(strcmp(str[j],str[m])>0) { strcpy(word,str[j]);strcpy(str[j],str[m]);strcpy(str[m],word);}
for(j=0;j<cnt;j++)
strcat(abc,str[j]);
strcpy(xx[i],abc);
}
}
void main()
{
clrscr() ;
if(ReadDat()) {
printf("数据文件ENG.IN不能打开!\n\007") ;
return ;
}
DelWord() ;
WriteDat() ;
}
int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;
if((fp = fopen("eng.in", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) xx[i][p - xx[i]] = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}
void WriteDat(void)
{
FILE *fp ;
int i ;
fp = fopen("ps6.out", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}
******************************************************************
eng.in(输入文件)
ISAM enhances the functionality of your programs through its
flexibility. If you add a section to a book, remove a few pages,
or rearrange paragraphs or sections, you have to recreate your
index, since the keywords must appear in relation to each other.
In this case, the relationship of the keywords to each other is
alphabetic order. A ISAM index changes automatian employee, or
change anything in a record, ISAM immediately updates all indexes.
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.
****************************************************************************
ps6.out(输出文件)
ISAMenhancesfunctionalityitsofprogramsthethroughyour
Ifaaaaddbookfewflexibilitypagesremovesectiontoyou
haveororparagraphsrearrangerecreatesectionstoyouyour
appeareachinindexkeywordsmustotherrelationsincetheto
Incaseeachiskeywordsofotherrelationshipthethethisto
AISAMalphabeticautomatianchangesemployeeindexororder
ISAMaallanythingchangeimmediatelyinindexesrecordupdates
Youananybecancreatefieldfieldsindexononseveraltoused
Theaaskeyonorpartsthatthereoftotogetherusewantyou
accessallowanddefineinindexeskeysquickrecordsspecifictoyou
AfterISAMafileforlongernoofordersprocessingsequentialyou
Additionanandcandeleteeffecthaveindexindexesitneednoyou
dataindexesononorotherrecordsthe
Youaeachfieldfieldidentifyininmayrecordthattouniquelywant
EmployeeForallexamplefilefrominotherrecordrecordsthethe
Numberassigndofieldifisnotnumbersamethetotwouniqueyou
anddifferentemployeesnevernumbersotherreassignthesetoyou
Ifabelongingemployeesfindmodifyorrecordthetotowishyou
determiningemployeefieldofsavesspecificthethisthoubleunique
correcthaverecordthewhetheryou
Ifadofieldfindfirsthavemustnotrecordtheuniqueyouyou
anddetermineiskeymatchesonerecordthethethewhetheryouyour
Ifagaincorrectfindisitmustnotoneotherssearchthetowantyou
Ifafieldhaveknowrecordsthatuniquewithinyouyouyouyour
ISAMallowandcandescriptionfactinincludekeyonlythethiswill
Forareemployeeexampleifkeysnumbersspecifythattheuniqueyou
ISAMaddchangefileforletsonlyorrecordsthetouniqueyou
alreadlydoemployeeexistfileintnotnumbersnumbersthatto
--------------------------------------------------------------------------------
This file is decompiled from a .CHM file
by an UNREGISTERED version of Easy CHM.
You can download Easy CHM at : www.eTextWizard.com
函数ReadDat()实现从文件IN.DAT中读取一篇英文文章存入到字符串数组xx中,请编制函数CharConvA(),其函数的功能是:以行为单位把字符串中的最后一个字符的ASCII值右移4位后加最后第二个字符的ASCII值,得到最后一个新的字符,最后第二个字符的ASCII值右移4位后加最后第三个字符的ASCII值,得到最后第二个新的字符,依此类推一直处理到第二个字符,第一个字符的ASCII值加原最后一个字符的ASCII值,得到第一个新的字符,得到的新字符分别存放在原字符串对应的位置上。最后已处理的字符串仍按行重新存入字符串数组xx中,最后调用函数writeDat()把结果xx输出到文件OUT10.DAT中。
原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格。
部分源程序存在文件prog1.c中。
请勿改动主函数main()和写函数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()
{ int i,j;
char p,c;
for(i=0;i<maxline;i++)
{ p=xx[i][strlen(xx[i])-1];
c=xx[i][0];
for(j=strlen(xx[i])-1;j>0;j--)
xx[i][j]=(xx[i][j]>>4)+xx[i][j-1];
xx[i][0]=p+c;
}
}
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;
fp=fopen("OUT10.DAT","w");
for(i=0;i<maxline;i++){
printf("%s\n",xx[i]);
fprintf(fp,"%s\n",xx[i]);
}
fclose(fp);
}
新题补充:
函数ReadDat()实现从文件ENG.IN中读取一篇英文文章存入到字符串数组xx中;请编制函数DelWord()分别按行删除空格、标点符号等非字符,并对每行的单词按升序排好序后存放回数组XX中,最后调用
函数WriteDat()把结果xx输出到文件PS6.OUT中。
原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格。
注意:部分源程序存放在文件prog1.c中。文章每行中的单词与单词之间用空格或其它标点符号分隔,每单词均小于20个字符。
请勿改动主函数main()、读数据函数ReadDat()和输出数据函数WriteDat()的内容。
#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 DelWord(void)
{ int i,j,k,m,cnt;
char *p, word[20],str[80][20],abc[80];
for(i=0;i<maxline;i++)
{ memset(word,0,20);
memset(str,0,80);
memset(abc,0,80);
k=cnt=0;
p=xx[i];
while(*p)
{ while(isalpha(*p)) word[k++]=*p++;
if(strlen(word)) strcpy(str[cnt++],word);
memset(word,0,20);
k=0;
while(!isalpha(*p)&&*p) p++;
}
for(j=0;j<cnt-1;j++)
for(m=j+1;m<cnt;m++)
if(strcmp(str[j],str[m])>0) { strcpy(word,str[j]);strcpy(str[j],str[m]);strcpy(str[m],word);}
for(j=0;j<cnt;j++)
strcat(abc,str[j]);
strcpy(xx[i],abc);
}
}
void main()
{
clrscr() ;
if(ReadDat()) {
printf("数据文件ENG.IN不能打开!\n\007") ;
return ;
}
DelWord() ;
WriteDat() ;
}
int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;
if((fp = fopen("eng.in", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) xx[i][p - xx[i]] = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}
void WriteDat(void)
{
FILE *fp ;
int i ;
fp = fopen("ps6.out", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}
******************************************************************
eng.in(输入文件)
ISAM enhances the functionality of your programs through its
flexibility. If you add a section to a book, remove a few pages,
or rearrange paragraphs or sections, you have to recreate your
index, since the keywords must appear in relation to each other.
In this case, the relationship of the keywords to each other is
alphabetic order. A ISAM index changes automatian employee, or
change anything in a record, ISAM immediately updates all indexes.
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.
****************************************************************************
ps6.out(输出文件)
ISAMenhancesfunctionalityitsofprogramsthethroughyour
Ifaaaaddbookfewflexibilitypagesremovesectiontoyou
haveororparagraphsrearrangerecreatesectionstoyouyour
appeareachinindexkeywordsmustotherrelationsincetheto
Incaseeachiskeywordsofotherrelationshipthethethisto
AISAMalphabeticautomatianchangesemployeeindexororder
ISAMaallanythingchangeimmediatelyinindexesrecordupdates
Youananybecancreatefieldfieldsindexononseveraltoused
Theaaskeyonorpartsthatthereoftotogetherusewantyou
accessallowanddefineinindexeskeysquickrecordsspecifictoyou
AfterISAMafileforlongernoofordersprocessingsequentialyou
Additionanandcandeleteeffecthaveindexindexesitneednoyou
dataindexesononorotherrecordsthe
Youaeachfieldfieldidentifyininmayrecordthattouniquelywant
EmployeeForallexamplefilefrominotherrecordrecordsthethe
Numberassigndofieldifisnotnumbersamethetotwouniqueyou
anddifferentemployeesnevernumbersotherreassignthesetoyou
Ifabelongingemployeesfindmodifyorrecordthetotowishyou
determiningemployeefieldofsavesspecificthethisthoubleunique
correcthaverecordthewhetheryou
Ifadofieldfindfirsthavemustnotrecordtheuniqueyouyou
anddetermineiskeymatchesonerecordthethethewhetheryouyour
Ifagaincorrectfindisitmustnotoneotherssearchthetowantyou
Ifafieldhaveknowrecordsthatuniquewithinyouyouyouyour
ISAMallowandcandescriptionfactinincludekeyonlythethiswill
Forareemployeeexampleifkeysnumbersspecifythattheuniqueyou
ISAMaddchangefileforletsonlyorrecordsthetouniqueyou
alreadlydoemployeeexistfileintnotnumbersnumbersthatto
--------------------------------------------------------------------------------
This file is decompiled from a .CHM file
by an UNREGISTERED version of Easy CHM.
You can download Easy CHM at : www.eTextWizard.com
回复Comments
{commenttime}{commentauthor}
{CommentUrl}
{commentcontent}