#include<stdio.h> void delete(int *p,int m) { int a[]={1,2,3,4,4,5,6},i; p=a; for(i=m-1;i<=5;i++) { *(p+i)=*(p+i+1); } *(p+i+1)="\0"; } main() { int a[]={1,2,3,4,4,5,6},m,*p,i; for(i=0;i<=6;i++) printf("%d",a[i]); printf("please input the position you want to delete"); scanf("%d",&m); delete(*p,m); for(p=&a;p<=(a+5);p++) printf("%d",*p); getch(); }
解决方案
15
#include<stdio.h> void mdelete(int *p,int m) { int i; for(i=m-1;i<=5;i++) { *(p+i)=*(p+i+1); } *(p+6)=0; } int main() { int a[]={1,2,3,4,4,5,6}; int m,i; int *p; for(i=0;i<=6;i++) printf("%d",a[i]); printf("please input the position you want to delete"); scanf("%d",&m); p = &a[0]; mdelete(p,m); for(i=0;i<=5;i++) printf("%d",a[i]); return 0; }
10
delete是关键词,不能用作函数名,换一个名字