第1题:
第2题:
假定输入的字符串中只包含字母和*号。请编写函数 fun(),它的功能是:除了尾部的,:号之外,将字符串中其他*号全部删除。形参p已指向字符串中最后一个字母。在编写函数时,不得使用C语言的字符串函数。
例如,若字符串中的内容为****A*BC*DEF*G******,删除后,字符串中的内容应当是ABCDEFG******。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio. h>
include<stdio. h>
void fun(char *a, char *p)
{
}
main ( )
char s[81],*t;
printf ("Enter a string: \n ");
gets (s);
t=s;
while (*t)
t++;
t--; /*指针t指向字符串尾部* /
while (*t== '*' )
t--; /*指针t指向最后一个字母*/
fun (s, t);
printf ("The string after deleted: \n");
puts (s);
}
第3题:
编写一个函数,该函数可以统计一个长度为2的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为asd asasdfg asd as zx67 asd mklo,子字符串为as,则应当输出6。
注意:部分源程序给出如下。
请勿改动主函数main和具他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
include <string.h>
int fun(char *str, char *substr)
{
}
main ( )
{
char str[81],substr[3];
int n;
clrscr ();
printf ("输入主字符串 ");
gets (str);
printf ("输入子字符串");
gets (substr);
puts (str);
puts (substr);
n=fun (shr, substr);
printf("n=%d\n ",n);
}
第4题:
/**/charstr1[128];/**/
/**/sum++;/**/
第5题:
1 编程:
用C语言实现一个revert函数,它的功能是将输入的字符串在原串上倒序后返回。
第6题:
假定输入的字符串中只包含字母和*号。请编写函数 fun(),它的功能是:只删除字符串前导和尾部的*号,串中字母之间的*号都不删除。形参n给出了字符串的K度,形参h给出了字符串中前导*号的个数,形参e给出了字符山中最后*号的个数。在编写函数时,不得使用c语言提供的字符串函数。
例如,若字符串中的内容为****A*BC*DEF*G*******,删除后,字符串中的内容则应当是A*BC*DEF*G。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仪在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
include <conio.h>
void fun (char *a;int n ,int h ,int e)
{
}
main ( )
{
char s [81],*t,*f;
int m=0,tn=0, fn=0;
printf("Enter a string :\n");
gets (s);
t=f=s;
while (*t)
{t++;m++; } /*m为字符串的长度*/
t--; /*指针t指身字符串尾部*/
while (*t=='*')
{t--; tn++; }
/*指针t指向最后一个字母,tn统计尾部'*'的个数*/
while (*f=='*' )
{f++;fn++;}
/*指针f指向第一个字母,tn统计导'*'的个数*/
fun( s, m, fn, tn);
printf ("The string after deleted: \n");
puts (s);
}
第7题:
请编写一个函数fun(),该函数的功能是:返回给定字符串中大写字母字符的个数。
如字符串"Hello World"中,大写字母的个数为2个。
注意:部分源程序已存在文件PROC5.CPP中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句。
文件PROC5.cpp的内容如下:
//PROC5.cpp
include<iostream>
include<string>
using namespace std;
int fun(char *str);
int main()
{
char str[ ]="Chinese Computer World";
cout<<fun(str)<<end;
return 0;
}
int fun(char *str)
{
//**********
}
第8题:
请编写函数fun(),该函数的功能是:统计一行字符串中单词的个数,作为函数值返回。一行字符串在主函数中输入,规定所有单词由小写字母组成,单词之间有若干个空格隔开,一行的开始没有空格。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<string. h>
include<stdio, h>
define N 80
int fun (char *s)
{
}
main ( )
{
char line [N];
int num=0;
printf ("Enter a string: \n ");
gets (line);
num=fun (line);
printf ("The number of word is: %d\n\n ",
num);
}
第9题:
有以下函数
函数的功能是( )。
A.统计x和y所指字符串中最前面连续相同的字符个数
B.查找x和y所指字符串中是否有’\0’
C.将y所指字符串赋给x所指存储空间
D.统计x和y所指字符串中相同的字符个数
第10题:
以下函数实现的功能是void fun (char *s){ char *p,*q,temp; p=s; q=s+ strlen(s)-1; while (p<q) { temp=*p; *p=*q; *p=temp; p++; q--; }}
A.将一个字符串首尾颠倒
B.计算字符串的长度
C.统计字符串中的空格个数
D.将字符串中的小写字母变成大写字母