更多"下列给定程序中,函数fun( )的功能是:在字符串str中找出ASCI"的相关试题:
[填空题]下列给定程序中,函数fun( )的功能是:在字符串str中找出ASCII码值最小的字符,将其放在第一个位置上,并将该字符前的原字符向后顺序移动。例如,调用fun( )函数之前给字符串输入fagAgBDh,调用后宁符串中的内容为AfaggBDh。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
/*************found************/
void fun(char p)
{
char min,*q;
int i=0;
min=p[i];
while (p[i]!=0)
{
if (min>p[i])
{
/*************found*************/
p=q+i;
min=p[i];
}
i++;
}
while(q>p)
{*q=*(q-1);
q--;
}
p[0]=min;
}
main( )
{
char str[80];
printf("Enter a string:");
gets(str);
printf("/nThe original string:");
puts(str);
fun(str);
printf("/nThe string after moving:");
puts(str);
printf("/n/n");
}
[简答题]填空题
请补充函数fun( ),该函数的功能是:把字符串str中的字符按字符的ASCII码降序排列,处理后的字符串仍然保存在原串中,字符串及其长度作为函数参数传入。
例如,如果输入“cdefgh”,则输出为“hgfedc”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include
#define N 80
void fun(char s[],int n)
{
int i, j;
char ch;
for(i=0;i
[填空题]请补充函数fun( ),该函数的功能是:把ASCII码为奇数的字符从字符串str中删除,结果仍然保存在字符串str中。字符串str从键盘输入,其长度作为参数传入函数fun( )。
例如,输入“abcdef”,输出“bdf”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio.h>
#define N 80
void fun(char s[],int n)
{
int i, j;
j=0;
for(i=0; 【1】 ;i++)
{
if( 【2】 )
s [j++]-s [i];
}
【3】 ;
}
main ( )
{
int i=0, strlen=0;
char str [N];
clrscr ( );
printf ("/nInput a string: /n");
gets (str);
while (str [i] !=’/0’)
{
strlen++;
i++;
}
fun(str, strlen);
printf("/n*** display string ***/n");
puts (str);
}
[填空题]下面的函数strcat(str1,str2)实现将字符串str2拼接到字符串str1后面的功能。请填空使之完整。
char*strcat(str1,str2)
char*str1,*str2;
{ char*t=str1;
while( 【16】 )str1++;
while( 【17】 );
return(t);}
[填空题]下列给定程序中函数fun的功能是:统计substr所指的字符串在str所指的字符串中出现的次数。
例如,若字符串为aaas 1kaaas,子字符串为as,则应输出2。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
int fun(char*str,char*substr)
int i,j,k,num=0;
/*********found*********/
for(i=0,str[i],i++)
for(j=i,k=0;
substr[k]==str[j];
k++,j++)
/*********found*********/
If(substr[k+1]==’/0’)
num ++;
break;
return num;
main( )
char str[80],substr[80];
printf("Input a string:");
gets(str);
printf("Input a substring:");
gets(substr);
printf("%d/n".fun(str,substr));
[填空题]下列给定程序中,函数fun( )的功能是将字符串s中位于偶数位置的字符或ASCII码为奇数的字符放入字符串t中(规定第一个字符放在第0位中)。
例如:字符串中的数据为ADFESHDI,则输出应当是 AFESDI。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
#define N 80
/************found*************/
void fun(char s,char t[])
int i,j=0;
for(i=0;i<strlen(s);i++)
/*********found*+************/
if(i%2=0 || s[i]%2!=0)
t[j++]=s[i];
t[j]=’/0’;
main( )
char s[N],t[N];
clrscr( );
printf("/nPlease enter string s:");
gets(s);
fun(s,t);
printf("/nThe result is:%s/n",t);
[填空题]请补充main函数,该函数的功能是:把字符串str1中的非空格字符拷贝到字符串str2中。
例如,若sffl=“glad to see you!”,
则str2=“gladtoseeyou!”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#define N 80
main( )
{
static char strl [N] ="glad to see you!";
char str2 IN];
int i=0, j=0;
clrscr ( );
printf("/n***** strl*****/n ");
puts (str1);
while (str1 [i] )
{
if(【1】)
str2 [J++] =strl [i];
【2】;
}
printf("/n***** str2 *****/n ");
for (i=0; i<j; i++)
printf ("%c", str2 [i] );
}
[填空题]请补充函数fun( ),该函数的功能是:把从主函数中输入的字符串str2接在字符串str1的后面。
例如:str1=“How do”,str2=“you do”,结果输出:How do you do
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define N 40
void fun(char *str1,char *str2)
{
int i=0;
char *p1=str1;
char *p2=str2;
while( 【1】 )
i++;
for( ; 【2】 ;i++)
*(p1+i)= 【3】 ;
*(p1+i)=’/0’;
}
main( )
{
char str1[N],str2[N);
clrscr( );
printf("*****Input the string str1 & str2*****/n");
printf("/nstr1:");
gets(str1);
printf("/nstr2:");
gets(str2);
printf("**The string str1 & str2**/n");
puts(str1);
puts(str2);
fun(str1,str2);
printf("*****The new string *****/n");
puts(str1);
}
[填空题]请补充函数fun( ),该函数的功能是:把从主函数中输入的字符串str2倒置后接在字符串str1后面。
例如:str1=“How do”,str2=“od uoy”,结果输出:“How do you do”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define N 40
void fun(char *str1,char *str2)
int i=0,j=0,k=0,n;
char ch;
char *p1=str1;
char *p2=str2;
while(*(p1+i))
i++;
while(*(p2+j))
j++;
n= 【1】 ;
for(;k=j/2;k++,j--)
ch=*(p2+k);
*(p2+k)=*(p2+j);
*(p2+j)=ch;
【2】 ;
for(; 【3】 ;i++)
*(p1+i)=*p2++;
*(p1+i)=’/0’;
main( )
char str1[N],str2[N];
int m,n,k;
clrscr( );
printf("***Input the string str1 & str2
***/n");
printf("/nstr1:");
gets(str1);
printf("/nstr2:");
gets(str2);
printf("***The string str1 & str2 ***/n");
p
[填空题]下列给定程序中,函数fun的功能是:将形参S所指字符串中下标为奇数的字符取出,并按ASCII码大小递增排序,将排序后的字符存入形参P所指的字符数组中,形成一个新串。
例如,形参s所指的字符串为“baawrskjghzlicda”,执行后p所指字符数组中的字符串应为“aachjlsw”。
请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
void fun(char*s,ehar*p)
int i,j,n,x,t;
n=0;
for(i=0;s[i]!=’/0’;i++)n++;
for(i=1;i<n-2;i=i+2)
/***********found*********/
______;
/*************found*************/
for(j=______+2;j if(s[t]>s[j])t=j;
if(t!=i)
x=s[i];
s[i]=s[t];
s[t]=x;
for(i=1,j=0;i<n;i=i+2j++)
p[j]=s[i];
/***********found*********/
p[j]=______;
main( )
char s[80]="baawrskjghzlicda",p[50];
printf("/nThe original string is:%s/n",s);
fun(s,p);
printf("/nThe result is:%s/n",p);
[填空题]下列给定程序中,函数fun( )的功能是逐个比较a,b两个字符串对应位置中的字符,把ASCII值小或相等的字符依次存放到c数组中,形成一个新的字符串。
例如:a中的字符串为fshADfg,b中的字符串为sdAEdi,则c中的字符串应为fdAADf。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <strinq.h>
void fun(char *p,char *q,char *c)
int k=0;
while(*p || *q)
/**********found**************/
if (*p<=*q)
c[k]=*q;
else c[k]:*p;
if(*p) p++;
if(*q) q++;
/**+**********found**************/
k++
main( )
char a[10]="fshADfg",b[10]="sdAEdi",
c[80]=’/0’);
fun(a,b,c);
printf("The string a:");puts
- (a);
printf("The string b:");puts - (b);
printf("The result:");puts - (c);
[填空题]给定程序MODI1.C中函数fun的功能是:将s所指字符串中位于奇数位置的字符或ASCII码为偶数的字符放入t所指数组中(规定第一个字符放在第0位中)。
例如,字符串s中的数据为:AABBCCDDEEFF,则字符串t中的数据为:ABBCDDEFF。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
文件MODI1.C内容如下:
#include<stdio.h>
#include<string.h>
#define N 80
void fun(char *s,char t[])
int i,j=0,n;
n=strlen(s);
for(i=0;i<n;i++)
/**********found**********/
if(i%2&&s[i]%2==0)t[j++]=s[i];
/**********found**********/
t[i]=’/0’;
void main( )
char s[N],t[N];
printf("/nPlease enter string s:");
gets(s);
fun(s,t);
printf("/nThe result is: %s/n",t);