求 C 源代码!!!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/05/06 10:18:52
题目一. 编写一个程序,从键盘读取两个字符串(以回车结束),调用函数strCat,将第二个字符串连接到第一个字符串尾部并输出。
练习目的:字符数组,指针和数组的关系
要求:设计一个函数
int strCat(char string1[],char string2[],……)
函数功能:将string2指向的字符数组中存放的字符串复制到string1指向的字符数组中,追加到原有的字符串后面。
函数参数说明:string1:指向第一个字符串;string2:指向第二个字符串;
程序运行效果要求如下:
请输入第一个字符串:Where there is life,
请输入第二个字符串:there is hope.
合并后的字符串是:Where there is life,there is hope.

题目二、编写一个程序,输入一个字符串,以回车键结束,如:123xh368jkh *12///789jjkl90,要求调用函数find,将字符串中的数字合并并保存到整型数组中,并输出整数中的最大值和最小值。
int find(char string[], int elementSize, int array[], int arraySize, int * maxPtr, int * minPtr)
函数功能:把string指向的字符串中连续数字合并,并作为整数存入array指向的整型数组中,同时,统计整数中的最小值和最大值,用指针maxPtr和minPtr返回给主程序。
函数参数说明:string:指向字符数组;elementSize:string指向的字符串长度(不包括字符串结束符‘\0’);array:指向整型数组;arraySize:数组array的长度;maxPtr:指向调用函数中存放最大值变量的指针;minPtr:指向调用函数中存放最小值变量的指针;
函数返回值:返回array中有效整数的个数。
练习目的:一维字符数组/整型数组操作、模拟传引用调用
要求:
字符数组的长度和整型数组的长度要求用常量来定义,方便以后对数组长度的修改。且整型数组的长度要足够大。
程序

/*第一题 已经通进上机测试*/
#include<string.h>
int strcat1(char *p,char *a)
{
while(*p!='\0')
p++;

while(*a!='\0')
*(p++)=*a++;
}

main()
{
static char temp1[80],temp2[80];
gets(temp1);
gets(temp2);
strcat1(temp1,temp2);
printf("%s\n%s",temp1,temp2);
getch();
}
/*第二题意**********/
main()
{
static char temp[256],*p;
long int max=0,min=0,tempmax=0,tempmin=0;

gets(temp);
p=temp;

while(*p++!='\0')
if(*p>='0'&&*p<='9')
{
tempmax=tempmax*10;
tempmax+=*p-'0';
}
else
{
if(min==0&&max==0){max=tempmax;min=tempmax;}
if(tempmax>max){max=tempmax;}
if(tempmax<min){min=tempmax;}
tempmax=0;
}

printf("max=%ld,min=%ld",max,min);
getch();

}