回覆列表
  • 1 # 使用者8107137581681

    指標沒有分配空間可以使用嗎?

    定義指標是不分配空間的,在使用前你得初始化,讓它指向確定的地址才可以後續使用。

    函式中是沒法更改傳入變數指標地址的!但可以更改其中的內容.

    你的比較好像有問題,得不到所需要的:“從小到大”

    #include "stdio.h"

    #include "string.h"

    int main(int argc, char* argv[])

    {

    char *t;

    char *p1=NULL,*p2=NULL,*p3=NULL;

    char ch1[20]={0},ch2[20]={0},ch3[20]={0};

    p1=ch1;

    p2=ch2;

    p3=ch3;

    printf("No1:");

    scanf("%s",p1);

    fflush(stdin);

    printf("No2:");

    scanf("%s",p2);

    fflush(stdin);

    printf("No3:");

    scanf("%s",p3);

    fflush(stdin);

    if(strcmp(p1,p2)>0)

    {t=p1;p1=p2;p2=t;}

    if(strcmp(p1,p3)>0)

    {t=p1;p1=p3;p3=t;}

    if(strcmp(p2,p3)>0)

    {t=p2;p2=p3;p3=t;}

    printf("%s\n%s\n%s\n",p1,p2,p3);

    return 0;

    }

  • 中秋節和大豐收的關聯?
  • 暗黑2純召喚死靈法師裝備?