请大家帮忙看看,我究竟错在哪里,为什么执行后又是一闪?
#include <stdio.h>const size_t BUFFER_LEN = 512;
int main(void)
{
char buffer[BUFFER_LEN];
char *ps[3] = {NULL};
char *pbuffer = buffer;
int i = 0;
int index = 0;
for(i=0;i<3;i++)
{
printf("\nEnter %s character.\n",i>0?"another":"a");
ps[i] = &buffer[index];
for(index=0;index<BUFFER_LEN;index++)
{
if((*(pbuffer + index) = getchar())=='\n')
{
*(pbuffer+index++)='\0';
break;
}
if((index==BUFFER_LEN) && (*(pbuffer+index-1)!='\0') || (i<2))
{
printf("\nYOU ran out of space in the buffer.");
return 1;
}
}
}
printf("\nYou enter the string are:\n\n");
for(i=0;i<3;i++)
printf("%s\n",ps[i]);
printf("The buffer has %d characters unused.\n",BUFFER_LEN-index);
return 0;
}