#include"stdio.h"
#include"malloc.h"
#define Max 10000
int *k;//保存最初地址
typedef struct
{
int *elem;
int length;
int listsize;
}sqlist;
void Initlist1(sqlist &L)
{
L.elem=(int*)malloc(Max*sizeof(int));
L.length=0;
L.listsize=Max;
k=L.elem;
}
void Input(sqlist &L)
{
int i,n;
printf("How many do you want(1~10000):\n");
scanf("%d",&n);
printf("Please enter the number:\n");
for(i=0;i<n;i++)
{
scanf("%d",L.elem);
L.elem++;
L.length++;
}
}
void Display(sqlist L)
{
int i;
L.elem=k;
for(i=0;i<L.length;i++)
{
printf("%d ",*L.elem);
L.elem++;
}
printf("\n");
printf("L.length is %d",L.length);
printf("\n");
}
void search(int n,sqlist L)
{
int r=0,i;
for(i=0;i<L.length;i++)
{ r++;
if(n==*L.elem)
printf(" the number's coordinate is %d",r);
if((n!=*L.elem)&&(i==(L.length-1)))
printf(" the number is not in this Array");
}
}
void main()
{ int n,k=0;
char p;
sqlist L;
Initlist1(L);
Input(L);
Display(L);
printf("Do you want to search?(Y/N)\n");
scanf("%c",&p);
if(p=='y'||p=='Y')
{
printf("which number:\n");
scanf("%d",n);
search(n,L);
}
}
为什么电脑把
scanf("%c",&p);
忽略了。直接执行完成?