以下程序的功能是将字符串s中的数字字符放入d数组中,最后输出d中的字符串。例如,输入字符串:abcl2
第1题
以下函数的功能是删除字符串s中的所有数字字符,请填空。void dele(char *s){ int n=0,i; for(i=0;s[i];i++) if() s[n++]=s[i]; s[n]=;}
第2题
例如,形参s所指的字符串为:Abe@1x56*。程序执行后t所指字符数组中的字符串应为:A@156*。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANKl.C中。
不得增行或删行,也不得更改程序的结构!
第3题
请编写函数fun(),其功能是:将s所指字符串中下标为偶数的字符删除,串中剩余字符形成的新串放在t所指数组中。
例如,当s所指字符串中的内容为ABCDEFGHIJK,则在t所指数组中的内容应是BDFHJ。
注意:部分源程序给出如下。
请勿改动主函数main口其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio. h>
include<stdio .h>
include<string.h>
void fun(char *s,char t[])
{
}
main ()
char s[l00] ,t[l00];
clrscr ();
printf("%nPlease enter string S: ");
scanf("%s ",s);
fun(s,t);
prlntf("\nThe result is:%s\n ",t);
}
第4题
A.将字符串s1拷贝给s
B.将字符串s拷贝给s1
C.统计字符串s1中有效字符个数
D.将字符串s1连接到s末尾
第5题
请编写一个函数fun(),它的功能是将一个数字字符串转换为一个整数(不得调用C语言提供的将字符串转为整数的函数)。
例如,若输入字符串“-1234”,则函数把它转换为整数值 -1234。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
include <string.h>
long fun(char *p)
{
}
main ()
{
char s[6];
long n;
printf("Enter a string:\n");
gets(s);
n=fun(s);
printf("%ld\n",n);
}
第6题
例如,若s所指字符串中的内容为“ABCDEFGl2345”,其中字符C的ASCIl码值为奇数,在数组中的下标为偶数,因此必须删除;而字符l的ASCIl码值为奇数,在数组中的下标为奇数,因此不应当删除,其他依此类推。最后t所指的数组中的内容应是“BDFl2345”。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
第7题
请编写函数fun(),该函数的功能是:将M行N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。
例如,若二维数组中的数据为:
W WWW
S S S S
H H H H
则字符串中的内容应是WSHWSHWSHWSH。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<stdio.h>
define M 3
define N 4
void fun(char (*s)[N],char *b)
{
}
main()
{
char a[100],w[M][N]={{ 'W', 'W', 'W', 'W'},
{'S', 'S', 'S', 'S'},{'H', 'H', 'H', 'H'}};
int i,j;
printf("The matrix:\n");
for(i=0;i<M;i++)
{ for(j=0;j<N;j++)
printf("%3c",w[i][j]);
printf("\n");
}
fun(w,a);
printf("The A string:In");
puts(a);
printf("\n\n");
}
第8题
下列给定程序中,函数fun()的功能是;利用插入排序法对字符串中的字符按从小到大的顺序进行排序。插入法的基本方法是:先对字符串中的头两个元素进行排序,然后把第3个字符插入到前两个字符中,插入后前3个字符依然有序;再把第4个字符插入到前3个字符中,待排序的字符串已在主函数中赋予。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
试题程序:
include <String.h>
include <stdio.h>
define N 80
void insert(char *aa)
{ iht i, j, n; char ch;
n=strlen (aa);
for (i=1; i<n; i++)
/**********************************/
{ c=aa[i];
j=i-1;
while ((j>=0) && (ch<aa [j] ))
{ aa [j+l]=aa[j];
j--;
}
aa [j+l]=ch;
}
}
main ()
{ char a [N] = "QWERTYUIOPASDFGHJKIMNBVCXZ";
int i;
printf("The original string: %s\n",a);
insert (a);
printf("The string after sorting:
%s\n\n", a);
}
第9题
阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内。
【说明】
以字符流形式读入一个文件,从文件中检索出6种C语言的关键字,并统计、输出每种关键字在文件中出现的次数。本程序中规定:单词是一个以空格或'\t'、'\n'结束的字符串。其中6种关键字在程序中已经给出。
【程序】
include <stdio.h>
include <stdlib.h>
FILE *cp;
char fname[20], buf[100];
int NUM;
struct key
{ char word[10];
int count;
}keyword[]={ "if", 0, "char", 0, "int", 0,
"else", 0, "while", 0, "return", 0};
char *getword (FILE *fp)
{ int i=0;
char c;
while((c=getc(fp))!= EOF &&(1));
if(c==EOF)
return (NULL);
else
buf[i++]=c;
while((c=fgetc(fp))!=EOF && c!="&& c!='\t' && c!='\n' )
buf[i++]=c;
buf[i]='\0';
return(buf);
}
void lookup(char *p)
{ int i;
char *q, *s;
for(i=0; i<NUM; i++)
{ q=(2);
s=p;
while(*s && (*s==*q))
{ (3))
if((4))
{ keyword[i].count++;
break;
}
}
return;
}
void main()
{ int i;
char *word;
printf("lnput file name:");
scanf("%s", fname);
if((cp=fopen(fname, "r"))==NULL)
{ printf("File open error: %s\n", fname);
exit(0);
}
NUM=sizeof(keyword)/sizeof(struct key);
while((5))
lookup(word);
fclose(cp);
for(i=0;i<NUM;i++)
printf("keyword:%-20s count=%d\n",keyword[i].word,keyword[i].count);
}
第10题
下列程序的功能是:求出ss所指字符串中指定字符的个数,并返回此值。
例如,若输入字符串123412132,输入字符1,则输出3,请填空。
#include
#include
#define M 81
int fun(char *ss, char c)
{ int i=0;
for(; ();ss++)
if(*ss==c)i++;
return i;}
main()
{ char a[M], ch;
clrscr();
printf("\nPlease enter a string: "); gets(a);
printf("\nPlease enter a char: "); ch=getchar();
printf("\nThe number of the char is: %d\n", fun(a,ch));}