分类: C/C++
2008-10-02 14:39:08
//sorting test program1
#include
#include
#include
//main function
int main()
{
FILE *fp;//the pointer of file
char msg[50];
char sort[10];
int i=0,j,k,t;
char *token;
if((fp=fopen("1.txt","r"))==NULL)
{ printf("error\n");
return 1;
}
//read the file
while(fgets(msg,50,fp)!=NULL)
{
token = strtok(msg,",");
while(token!=NULL)
{
sort[i++]=atoi(token);
token=strtok(NULL,",");
}
}
//sort function
for(j=0;j
for(k=0;k if(sort[k]
t=sort[k];
sort[k]=sort[k+1];
sort[k+1]=t;
}
}
//print the sorted data
for(j=0;j printf("%d\n",sort[j]);
//system("pause");
fclose(fp);
return 0;
}