菜鳥請教各位老手 |
尚未結案
|
maiching33325
一般會員 發表:1 回覆:1 積分:0 註冊:2003-03-26 發送簡訊給我 |
最近再寫一個程式..目的是讀取檔案裡的數值然後由小到大排列
但我無法做到由小到大排列....請問哪裡寫的不對..懇請各位指教 String str="";
char fstr[20];
FILE *fp ;
fp = fopen(".\\file.txt","r");
str="編號\t數值A\t數值B\t數值C\t數值D\n";
while(!feof(fp)){
fscanf(fp,"%s",fstr);
str=str+fstr+"\t";
fscanf(fp,"%s",fstr);
str=str+fstr+"\t";
fscanf(fp,"%s",fstr);
str=str+fstr+"\t";
fscanf(fp,"%s",fstr);
str=str+fstr+"\n";
int i,j,x;
for(i=0;i<3;i ){
for(j=i 1;j<4;j ){
if(fstr[i]>fstr[j]){
x=fstr[i];
fstr[i]=fstr[j];
fstr[j]=x;
}
}
}
}
fclose(fp);
ShowMessage(str);
|
okiss
一般會員 發表:11 回覆:55 積分:13 註冊:2002-11-27 發送簡訊給我 |
引言: int i,j,x; for(i=0;i<3;i ){ for(j=i 1;j<4;j ){ //你這裡是string compare..@@..不對吧 if(fstr[i]>fstr[j]){ //應該先把char string轉成int x=fstr[i]; fstr[i]=fstr[j]; fstr[j]=x; } } } } fclose(fp); ShowMessage(str);把char string轉成int請用atoi這個函數... 不過,如果你可以用C 的話,建議你用fstream來open and close file 且array宣告成integer比較好...^^ |
maiching33325
一般會員 發表:1 回覆:1 積分:0 註冊:2003-03-26 發送簡訊給我 |
|
okiss
一般會員 發表:11 回覆:55 積分:13 註冊:2002-11-27 發送簡訊給我 |
atoi
-----------------------------------------------------------
Header File
stdlib.h Category
Conversion Routines, Math Routines Syntax
#include
|
sunex
一般會員 發表:9 回覆:7 積分:3 註冊:2003-03-18 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |