C gets问题
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ERRP(con,ret) do{\
if(con)\
ret;\
}while(0)\
int main(void)
{
char a[10],num;
int i = 10,j = 0;
int count = 0;
char *p = NULL,*prev = NULL;
while (1)
{
printf("please input %d words:",count+1);
gets(num);
if(num == 'p')
break;
p = (char *)malloc((count+1)*sizeof(char));
ERRP(NULL == p,return -1);
memmove(p,prev, sizeof(char)*(count));
p[count] = num;
free(prev);
prev = p;
count++;
}
putchar(10);
for(i=0;i<count;i++)
{
printf("[%c:%p]\n",p[i],&p[i]);
}
printf("\n");
free(p);
return 0;
}
char *gets(char *s);// gets函数的参数是一个字符串哦,
//你传一个char显然出问题
//建议换成
int getchar(void) ;//单个字节获取