错在哪里?
题目:#include<stdio.h>
#include<conio.h>
#include<malloc.h>
void main()
{
char * match(char *s,char ch);
char *p,*p1;
char c;
int n;
printf("input a number you want to use space :");
scanf("%d",&n);
printf("\n");
p=(char *)malloc(n);
printf("input a chararray that you want to:");
scanf("%s",p);
printf("\n");
printf("input a char you want to fine:");
scanf("%c",&c); //就在这里把scanf给跳过了,c的值输入不了,什么原因呢?
printf("\n");
p1=match(p,c);
printf("the new chararray is:");
printf("%s",p1);
printf("\n");
free((void *)p);
getch();
}
char * match(char *s,char ch)
{
int i=0;
while(s[i]!='\0')
{
if(s[i]==ch)
break;
i++;
}
return(s+i);
}