问题 多项选择题

下列程序的功能是:把s字符串中所有的字符左移一个位置,串中的第一个字符移到最后。请编制函数 chg(char*s)实现程序要求,最后调用函数readwriteDat()把结果输出到out63.dat文件中。
例如:s字符串中原有内容为Mn,123xyZ,则调用该函数后,结果为n,123xyZM。
注意:部分源程序已给出。
请勿改动主函数main()和输入输出函数readwriteDAT()的内容。
试题程序:
#include<conio. h>
#include<stdio. h>
#define N 81
void readwriteDAT(); void chg(char *s)

main ( )

char a [N];
clrscr ();
printf("Enter a string :");
gets (a);
printf("The original string is :");
puts (a);
chg (a);
printf("The string after modified :");
puts (a);
readwriteDAT ( );
void readwriteDAT()
int i;
char a [N];
unsigned char *p;
FILE *rf,*wf;
rf=fopen ("in63.dat", "r");
wf=fopen ("out63.dat", "w");
for (i=0; i<10;i++)
fgets (a, 80, rf);
p=strchr (a, ’ \n’ );
if(p) *p=0;
chg (a);
fprintf (wf, "%s\n", a);

fclose(rf);
fclose (wf);

答案

参考答案:void chg(char *s)
{
int i,strl;
char ch;
strl=strlen (s); /*求字符串的长度*/
ch=*s; /*将第一个字符暂赋给ch* /
for (i=O; i<strl-A; i++) /*将字符依次左移*/
*(s+i) =* (s+i+l);
* (s+strl-A) =ch; /*将第一个字符移到最后*/
}

解析:
(1) 数组中元素的移动。
(2) 指针的使用。
我们可以使用一个循环实现数组中所有字符元素的左移。这里要注意的足第1个字符要移至最后1个字符处,所以首先要将第1个字符保存。在移动时,要从左到右依次移动,否则,左侧的字符会在移动前被其右侧的字符覆盖。在这里使用了指针,初始时,指针指向数组的第1个元素,随着地址的增加指针指向数组后面的元素。例如,若地址加2,

单项选择题
改错题

短文改错。

     假定英语课上老师要求同桌之间交换修改作文,请你修改你同桌写的以下作文。文中共有10处

语言错误,每句中最多有两处。错误涉及一个单词的增加、删除或修改。

增加:在缺词处加一个漏字符号(A),并在其下面写出该加的词。

删除:把多余的词用斜线(\)划掉。

注意:1. 每处错误及其修改均仅限一词;

          2. 只允许修改10处,多者(从第11处起)不计分。

Dear Steve,

     You asked me to write you something about my visit the British Isles. I will tell you the culture of the

people of the British Isles.

     The culture of the British Isles is influenced by the culture of the people on the European Mainland many

centuries ago. In the fifth century, people from different part of north Europe settled in England, brought

their own culture and languages with them. Their languages formed the basis for English. Some of the native

population moved to the inland, mountainously parts of the islands, to Ireland, Scotland and Wales, which

they continued speaking their own languages. In 1066 England was conquered by the French. For the next a

few hundred years, the upper classes spoke French when the common people spoke English. The result of

this French influence was whether the English language ended up with many French words such as table,

animal and age.

     I will stop here, and hope me enjoy it.

                                                                                                                                      Best wishes,

                                                                                                                                       Lee

__________________________________________________________________________________