線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:832
推到 Plurk!
推到 Facebook!

請問陣列傳值給變數的問題

答題得分者是:fusung
lhc67
一般會員


發表:10
回覆:4
積分:2
註冊:2005-05-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-07-10 10:19:41 IP:140.115.xxx.xxx 未訂閱
int g,base=2,w; int sl; char str[]="kujhiu4jh int i; for(i=0;str[i]!=0;i++) if(isdigit(str[i]))  printf("%c",str[i]); printf("\n"); sl=str[]; 要怎麼把一個陣列 str[  ] 的值到變數sl,  請高手幫幫忙    下列的程式是十進位轉成 .......二進位..八進位..及十六進位,各位 可以跑跑看.... 現在的問題是要程式除了數字以外...其它都跳過不讀取 例如asdfghj4567kue difle 只讀4567並做進制轉換    #include  #include #include #include #include #include int main() { int g,base=2,w; int sl=4; if (base==8) { int i,y; char j[13]; for(i=1;i<13;i ){ j[i]=sl&7; sl=sl>>3; } for(y=12;y>0;y--){ printf("%d", j[y] ); } printf("\n"); } else if (base==2) { int i,y; char j[13]; for(i=1;i<13;i ){ j[i]=sl&1; sl=sl>>1; } for(y=12;y>0;y--){ printf("%d", j[y] ); } printf("\n"); } else if (base==16) { printf("%x",sl); } printf("\n"); } 發表人 - lhc67 於 2005/07/10 14:26:46 發表人 - lhc67 於 2005/07/10 15:05:07
fusung
中階會員


發表:26
回覆:169
積分:99
註冊:2003-11-25

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-07-10 12:37:14 IP:61.222.xxx.xxx 未訂閱
哈囉,lhc67:    我已經將字串陣列含有數字的部分依序傳給變數sl,    至於sl進制轉換再請你自行修改,希望下面的程式對你有所幫助。 < class="code"> int main(int argc, char* argv[]) { int i,base, sl; char str[]="asdfghj012345679kuedifle "; printf(">> base(進制) = "); scanf("%d",&base); for(i=0;str[i]!=0;i ){ if(isdigit(str[i])){ sl = str[i]-48; printf("再對%d做%d進制轉換\n",sl,base); } } printf("\n"); system("pause"); return 0; } The first step toward proving things for yourself is to understand how others have done it before! 發表人 - fusung 於 2005/07/10 16:13:23
------


The first step toward proving things for yourself is to understand how others have done it before!

系統時間:2024-05-18 22:20:20
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!