#include <stdio.h>
#include <stdlib.h>
int main(){
    char *p,*tmp;
    int a;
    p=malloc(50);
    p[0]='a';
    p[1]='b';
    p[2]='c';
    p[3]='\0';
    while(1){
        printf("請輸入要形成的空間:");
        scanf("%d",&a);
        if((tmp=realloc(p,a))==NULL){
            puts(">>> realloc() 執行失敗");
            continue;
        }else if(tmp!=p){
            puts(">>> 起始記憶體位址已變更");
            p=tmp;
        }else{
            puts(">>> 在原先的位址順利完成");
        }
        printf("string: %s\n",p);
    }
    return 0;
}