Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1677521
  • 博文数量: 210
  • 博客积分: 10013
  • 博客等级: 上将
  • 技术积分: 2322
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-25 15:56
文章分类

全部博文(210)

文章存档

2011年(34)

2010年(121)

2009年(37)

2008年(18)

我的朋友

分类: 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;
}

阅读(1303) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~