#include
#include
#include
#define MAX_N 20
#define MAX_DST 200
char *sub_str_cp(char *src, char *dst, int m)
{
char *dst_o = dst;
if (NULL==src || NULL==dst ||
strlen(src)>MAX_N || m<1 || m>MAX_N)
return NULL;
src += m-1;
while (*(dst++) = *(src++));
return dst_o;
}
char *str_join(char *src1,char *src2,char *dst)
{
char *dst_o = dst;
if (NULL==src1 || NULL==src2 || NULL==dst)
return NULL;
while (*(dst++) = *(src1++));
dst -= 1;
while (*(dst++) = *(src2++));
return dst_o;
}
int ins_sort(int iArr[],int num,int new_one)
{
if (NULL == iArr || num+1 >= MAX_DST)
return 0;
int *p = iArr + num - 1;
while (p >= iArr && new_one < *p)
{
*(p+1) = *(p);
p--;
}
*(p+1) = new_one;
return num+1;
}
// 删除从字符数组dst中首次出现的字符del_c
char *del_char(char *dst,char del_c)
{
int idx = 0;
char *dst_o = dst;
if (NULL == dst) return NULL;
while ('\0' != *dst)
{
if (*(dst++) != del_c)
*(dst_o + idx++) = *(dst-1);
}
return dst_o;
}
int main()
{
char src[MAX_N+1],src1[MAX_N+1],src2[MAX_N+1];
char dst[MAX_DST+1];
char cA;
int ins_new,num_of_iArr,iA;
int iSort[MAX_DST] = {12,23,32,55,100,101,205,309};
// sub str cp
int m;
printf("subject 1. strcpy\n");
printf("input string(length <= %d):",MAX_N);
scanf("%s",src);
printf("copy string from position(1=
printf("string have been copied:%s\n",sub_str_cp(src,dst,m));
// str join
printf("\nsubject 2. strcat\n");
printf("input string1(length <= %d):",MAX_N);
scanf("%s",src1);
printf("input string2(length <= %d):",MAX_N);
scanf("%s",src2);
printf("string after joining:%s\n",str_join(src1,src2,dst));
// array sort
printf("\nsubject 3. sorting\n");
num_of_iArr = 8;
printf("oringinal array:\n");
for (iA=0; iA
printf("\ninsert an integer:");
scanf("%d",&ins_new);
num_of_iArr = ins_sort(iSort,num_of_iArr,ins_new);
printf("array after sorting:\n");
for (iA=0; iA
printf("\n");
// del elem of array
getchar();
printf("\nsubject 4. del\n");
printf("string:%s\n",dst);
printf("del ? character from above string:");
scanf("%c",&cA);
printf("string after deleting %c:%s\n",cA,del_char(dst,cA));
return 0;
}
好吧,我来做:
#include
/*把s中的所有x删除,并返回剩下元素数*/
int DelElem(int *s,int n,int x)
{
int i,j;
for(i=0;i
{
for(j=i;j
}
return n;
}
int main( )
{
int a[]={2,6,4,5,6,7,8,10,5,6,7};
int n;
n=sizeof(a)/sizeof(int);
n=DelElem(a,n,6);
for(i=0;i
printf("\n");
return 1;
}
好了,请给分,虽然没有调试,但是应该没有什么错误,呵呵.
四个大题,多得都不敢做啊