請問陣列傳值給變數的問題 |
答題得分者是:fusung
|
lhc67
一般會員 發表:10 回覆:4 積分:2 註冊:2005-05-12 發送簡訊給我 |
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
|
fusung
中階會員 發表:26 回覆:169 積分:99 註冊:2003-11-25 發送簡訊給我 |
哈囉,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! |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |