#include
int main()
{
char* buf = NULL; //動態分配 //char buf[1024]; //指定長度
char ch;
int len = 0,i;
printf("Please input some line:\n");
while(scanf("%c",&ch)==1 && ch!=EOF && ch!="#"){ //定義一個結束符或者ctrl+z/d
//動態的實現
buf = (char*)realloc(buf,sizeof(char)*(len+1));
buf[len++] = ch;
//buf[len++] = ch; //指定長度
}
printf("reverse your input to print:\n");
for(i=len-1;i>=0;i--){
printf("%c",buf[i]);
free(buf); //動態清除
return 0;
#include
#include
int main()
{
char* buf = NULL; //動態分配 //char buf[1024]; //指定長度
char ch;
int len = 0,i;
printf("Please input some line:\n");
while(scanf("%c",&ch)==1 && ch!=EOF && ch!="#"){ //定義一個結束符或者ctrl+z/d
//動態的實現
buf = (char*)realloc(buf,sizeof(char)*(len+1));
buf[len++] = ch;
//buf[len++] = ch; //指定長度
}
printf("reverse your input to print:\n");
for(i=len-1;i>=0;i--){
printf("%c",buf[i]);
}
free(buf); //動態清除
return 0;
}