code.club

標題: 仿gets()的函數 [打印本頁]

作者: enter    時間: 2015-2-27 18:55
標題: 仿gets()的函數
本帖最後由 enter 於 2015-2-27 21:22 編輯

#include <stdio.h>

char igets(char *ptr);

int main(void)
{
char x[20];

printf("Enter a sentence:\n");
igets(x);
printf("%s",x);
return 0;
}

char igets(char *ptr)
{
do
{
scanf("%c",ptr);
ptr++;
}
while(*(ptr-1)!='\n'); //因為上面已經ptr++,所以這邊要減一向前回一個。
  *(ptr-1)='\0';
}




歡迎光臨 code.club (http://code.club/) Powered by Discuz! X3.2