| 會員 ![]() | 【求助】幾題C問題,有關有關getch'陣列 1. #include <stdio.h> void main() { char c=0; int i,loc=0; printf("A\r"); while(c!=27) { c=getchar(void); if(c==75) { loc--; } if (c==77) { loc++; } } loc+=10; loc%=10; printf(" \r"); for(i=0;i<loc;i++) printf(" "); printf("A\r"); } 2. #include <stdio.h> #define getrand(x) random(x) void main() { int arr[10]; float random(int); int i,j,x; for(i=0;i<10;i++) { x=100; j=getrand(x); arr[i]=j; printf("arr[%d]=%d\n",i,arr[i]); } } 1. 題:執行時,按向左'右鍵.螢幕上的字母A會左右移動 問:執行時,按左右鍵沒有任何反應 2. 題:寫函式getrand(),呼叫隨機函式產生10個(0~100)數值,並將產生數值放致陣列中 問:產生錯誤.unresolved external symbol "float __cdecl random(int)" (?random@@YAMH@Z) 謝謝回答 |
| 回覆 |
| 會員 ![]() | 1.左右鍵無法由getch取得鍵值,必須引用bios.h 2.直接函式andom即可 #include <stdio.h> #include <stdlib.h> void main() { int arr[10]; int i,j,x; randomize(); for(i=0;i<10;i++) { arr[i]=random(100); printf("arr[%d]=%d\n",i,arr[i]); } } |
| 回覆 |
| 會員 ![]() | 嗯....找不到bios.h耶..要去那裡找呢 謝謝回答 |
| 回覆 |
| 會員 ![]() | 引用:
您的開發環境為何? | |
| 回覆 |
| 會員 ![]() | 我是用Visual C++跑的 |
| 回覆 |
| 會員 ![]() | #include <stdio.h> #include <stdlib.h> struct list { int data; struct list *next; }; typedef struct list node; typedef node *link; void main() { link ptr,head,tail; int num,i; tail=(link)malloc(sizeof(node)); tail->next=NULL; ptr=tail; printf("input\n"); for(i=0;i<=4;i++) { scanf("%d",&num); ptr->data=num; head=(link)malloc(sizeof(node)); head->next=ptr; ptr=head; } ptr=ptr->next; printf("list\n"); while(ptr!=NULL) { printf("the value is %d\n",ptr->data); ptr=ptr->next; } } --------------- 1.tail=(link)malloc(sizeof(node));這是指tail分配一個位址是node的記憶体大小的開頭嗎 2. ptr->data=num;/*將輸入至ptr->data*/ head=(link)malloc(sizeof(node));/*head=node大小*/ head->next=ptr;/*為何將head->next=ptr然後又將ptr=head呢*/ ptr=head; 在記憶体是的圖形是否如下呢? |----|----|----| |-----|-----|--- | |head|data|next|-- -> |ptr |data |next|-->NULL |----|----|----| |-----|-----|--- | |--------------------> | |-->num |>tail 謝謝回答 |
| 回覆 |
| |
| XML | RSS 2.0 | RSS |
本論壇所有文章僅代表留言者個人意見,並不代表本站之立場,討論區以「即時留言」方式運作,故無法完全監察所有即時留言,若您發現文章可能有異議,請 email :[email protected] 處理。