深圳iso9001认证公司:C语言函数菜单的问题
作业2:有一个字符串,包含n个字符。写一函数,将此字符串从第m个字符开始的全部字符复制成另一个字符串。
作业3:将n个数按输入时顺序的逆序排列,用函数实现。
这是原来的那个菜单,上面3道题目要添加到这里面去。
#define MAX 100
#include"stdio.h"
#include"stdlib.h"
#include"conio.h"
void clear()
{clrscr();
gotoxy(16,4);
textbackground(14);
textcolor(4);
}
void good_bye()
{clear();
printf("\n\n\n\n\n\t\t\t Program End,GOOD BYE!");
getchar();
}
void print_randnum(a,n)
int a[];
int n;
{int i;
clear();
printf("\n\n\t\t output randnum:\n\n\t\t");
for(i=1;i<=n;i++)
{printf("%6d",a);
if(i%6==0) printf("\n\t\t");
}
printf("\n");
getchar();
getchar();
}
void creat_randnum(a,range,n)
int a[];
int range,n;
{int i;
for(i=1;i<=n;i++)
a=random(range);
printf("\n\n\t\t output randnum:\n\n\t\t");
for(i=1;i<=n;i++)
{printf("%6d",a);
if(i%10==0)printf("\n\t\t");
}
printf("\n");
getchar();
getchar();
}
int menu_select()
{ char c;
int n;
clear();
printf(" Shuzu de paixu yunsuan:\n\n\n");
printf("\t\t\t1. Chansheng suiji shuzu\n");
printf("\t\t\t2. Shuchu suijishu shuzu\n");
printf("\t\t\t3. \n");
printf("\t\t\t4. \n");
printf("\t\t\t5. \n");
printf("\t\t\t6. \n");
printf("\t\t\t0. Exit\n");
do{printf("\n\t\t\t Enter 0-6 select:");
c=getchar();
n=c-48;
}while((n<0)||(n>6));
return(n);
}
void create()
{int b[MAX],r[MAX];
void creat_randnum();
int range1,i,k=MAX;
clear();
printf("Jianli suijishu hanshu(press any key start):\n\n\n\t\t");
printf("\n\t\t shuru suijishu de fanwei range1=\n\t");
scanf("%4d",&range1);
creat_randnum(b,range1,k);
for(i=1;i<=MAX;i++)
r=b;
}
void creat_randnum1(a)
int a[MAX];
{int n,range;
int i;
clear();
printf("chansheng suiji zhengshu chengxu\n\n");
printf("\n\t\t Shuru suijishu de geshu(n<=200):");
scanf("%d",&n);
printf("\n\t\t Shuru suijishu de fanwei range=");
scanf("%d",&range);
for(i=1;i<=n;i++)
a=random(range)+1;
printf("\n\n\t\t Shuchu suiji zhengshu:\n\n\t\t");
for(i=1;i<=n;i++)
{printf("%6d",a);
if(i%5==0)printf("\n\t\t");
}
printf("\n");
getchar();
getchar();
}
main()
{int a[MAX],b[MAX],kk;
int range=999,n=MAX;
do
{kk=menu_select();
switch(kk)
{case 1:{creat_randnum(a,range,n);break;}
case 2:{print_randnum(a,n);break;}
case 3:{break;}
case 4:{break;}
case 5:{break;}
case 6:{break;}
case 0:{good_bye();exit(0);}
}
getchar();
getchar();
}while(kk!=0);
}
=======================================================
恳求各位大人出手相救。。。
/**********************************
完整的代码,只需编译即可运行!
**********************************/
#define MAX 100
#include"stdio.h"
#include"stdlib.h"
#include"conio.h"
#include"math.h"
#include"string.h"
int length(char* a )
{ return strlen(a);
}
void copy(char *a,char*b,int n,int m)
{ int i,j;
for(i=m,j=0;i<n;i++,j++)
b[j]=a[i];
b[j]='\0';
}
void Inv(int* a,int n)
{ int i,*b;
b=(int*)malloc(n*sizeof(int));
for(i=0;i<n;i++)
b[i]=a[n-i-1];
for(i=0;i<n;i++)
a[i]=b[i];
}
void clear()
{clrscr();
gotoxy(16,4);
textbackground(14);
textcolor(4);
}
void good_bye()
{clear();
printf("\n\n\n\n\n\t\t\t Program End,GOOD BYE!");
getchar();
}
void print_randnum(int a[],int n)
{int i;
clear();
printf("\n\n\t\t output randnum:\n\n\t\t");
for(i=1;i<=n;i++)
{printf("%6d",a);
if(i%6==0) printf("\n\t\t");
}
printf("\n");
getchar();
getchar();
}
void creat_randnum(int a[],int range,int n)
{int i;
for(i=1;i<=n;i++)
a[i]=random(range);
printf("\n\n\t\t output randnum:\n\n\t\t");
for(i=1;i<=n;i++)
{printf("%6d",a);
if(i%10==0)printf("\n\t\t");
}
printf("\n");
getchar();
getchar();
}
int menu_select()
{ char c;
int n;
clear();
printf(" Shuzu de paixu yunsuan:\n\n\n");
printf("\t\t\t1. Chansheng suiji shuzu\n");
printf("\t\t\t2. Shuchu suijishu shuzu\n");
printf("\t\t\t3. Shuchu zifu changdu\n");
printf("\t\t\t4. fuzhi zifu shuzu\n");
printf("\t\t\t5. Lixu shuchu shuzhu\n");
printf("\t\t\t6. Nothing\n");
printf("\t\t\t0. Exit\n");
do{printf("\n\t\t\t Enter 0-6 select:");
c=getchar();
n=c-48;
}while((n<0)||(n>6));
return(n);
}
void create()
{int b[MAX],r[MAX];
void creat_randnum();
int range1,i,k=MAX;
clear();
printf("Jianli suijishu hanshu(press any key start):\n\n\n\t\t");
printf("\n\t\t shuru suijishu de fanwei range1=\n\t");
scanf("%4d",&range1);
creat_randnum(b,range1,k);
for(i=1;i<=MAX;i++)
r[i]=b[i];
}
void creat_randnum1(a)
int a[MAX];
{int n,range;
int i;
clear();
printf("chansheng suiji zhengshu chengxu\n\n");
printf("\n\t\t Shuru suijishu de geshu(n<=200):");
scanf("%d",&n);
printf("\n\t\t Shuru suijishu de fanwei range=");
scanf("%d",&range);
for(i=1;i<=n;i++)
a[i]=random(range)+1;
printf("\n\n\t\t Shuchu suiji zhengshu:\n\n\t\t");
for(i=1;i<=n;i++)
{printf("%6d",a);
if(i%5==0)printf("\n\t\t");
}
printf("\n");
getchar();
getchar();
}
void fun1(char*ch)
{ printf("Input a string:\n");
scanf("%s",ch);
printf("%d\n",length(ch));
}
void fun2(char a[],char b[])
{
int n, m;
printf("Input string a:\n");
scanf("%s",a);
n=strlen(a);
printf("Input the insert position:\n");
scanf("%d",&m);
copy(a,b,n,m);
printf("Now b string is:\n%s\n",b);
}
void fun3()
{ int N[1000];
int n,i;
printf("Input the length of the array\n");
scanf("%d",&n);
printf("Input the the array\n");
for(i=0;i<n;i++)
scanf("%d",&N[i]);
printf("After inverse,the array is:\n");
Inv(N,n);
for(i=0;i<n;i++)
printf("%d ",N[i]);
printf("\n");
}
main()
{int a[MAX],b[MAX],kk;
int range=999,n=MAX;
char ch[1000],ac[1000],bc[1000];
do
{kk=menu_select();
switch(kk)
{case 1:{creat_randnum(a,range,n);break;}
case 2:{print_randnum(a,n);break;}
case 3:{fun1(ch);break;}
case 4:{fun2(ac,bc);break;}
case 5:{fun3();break;}
case 6:{break;}
case 0:{good_bye();exit(0);}
}
getchar();
getchar();
}while(kk!=0);
}
int leng(char *a)
{int i;
for(i=0;*(a+i)!='\0';i++);
return i;}
char(char *a,char *b,int m)
{a=a+m;
for(;*a!='\0';b=a,b++,a++);}
//求长度
int Length(char* szSrc)
{ static int nCount=0;
while(*(szSrc+nCount)!='\0')
nCount++;
return nCount;
}
//有一个字符串,包含n个字符。写一函数,将此字符串从第m个字符开始的全部字符复制成另一个字符串。
char* Mid(char* szSrc,int n1,int n2)
{
static char sz[1024];
memset(sz,0,sizeof(sz));
strncpy(sz,szSrc+n1,n2-n1+1);
return sz;
}
//逆序 数字逆序要把长度也送进去
void changestr(char *szSrc)
{
static int nCount=0;
do(*(szSrc+nCount)!='\0')
nCount++;
for(int i=0; i<=nCount/2;i++)
{
char ch;
ch =*(szSrc+i);
*(szSrc+i) = *(szSrc+nCount-i);
*(szSrc+nCount-i)=ch;
}