Chinaunix首页 | 论坛 | 博客
  • 博客访问: 34241
  • 博文数量: 10
  • 博客积分: 270
  • 博客等级: 二等列兵
  • 技术积分: 105
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-05 21:42
文章分类

全部博文(10)

文章存档

2012年(10)

我的朋友

分类: C/C++

2012-01-12 10:32:42

#include
#include
#include
#include
#include

int main()
{
   FILE * fp;
   FILE * nlenF;
   int dwRetValue;
   int  read_length = 0;
   long hFile;
   char FileName[500];
   char tmp[100];
   char *ptr;
   int Num=9000000;
   int Flag=1;
   DIR   *dirp;
   off_t  Flong=0;
   off_t  Flenth=0;
   char maxFileName[100];
   bzero(maxFileName,100);
   system("mkdir /thunderstone");
   system("mkdir /thunderstone/medias");
   if((dirp = opendir("/thunderstone/medias")) == NULL)
    {
     printf("创建失败");
    return 0;
   }
   char maxFileNamee[100];  
   strcpy(FileName,"/medias.txt");
  // fp = fopen(FileName,"r");//用该函数 lseek 返回 错误
   fp=open(FileName,O_RDONLY);
   lseek(fp,0,SEEK_SET);
   Flong= lseek(fp,0,SEEK_END);
   printf("\n测试文件大小=%ld\n",Flong);
   if(fp)
    close(fp);
   if(Flong>0)
        {
        Flenth=Flong+100;
        int count=0;
        int source=0;
        int destnation=0;
        char buffer[Flenth];
        bzero(buffer, Flenth);      
        fp = fopen(FileName,"r");//用该函数 lseek 返回 错误
        printf("\n打开文件\n");
        if(NULL != fp)
           {
             dwRetValue = ftell(fp);
             read_length = fread(buffer, sizeof(char), Flenth, fp);
             fclose(fp);
             printf("\n读取数据\n");  
           }
        else
           {
            printf("\n打开文件失败!\n");
           }
        printf("\n开始替换\n");
       // while(Flag)
       while(Flong--)
           {
            if(buffer[source++]=='.')
             {
           
                if(buffer[source++]=='m')
                 {
                  
                   if(buffer[source++]=='p')
                    {
                    
                      if(buffer[source++]=='g')
                       {
                         Num++;
                         count++;
                         bzero(tmp, 100);                             
                         sprintf(tmp,"%d.mpg",Num);
                         strncpy(&buffer[source-11],tmp,11);                       
                       }                   
                    }                    
                 }     
              } 
           }
       printf("\n记录%d条\n",count);
       printf("\n开始写入数据\n");
       nlenF = fopen("/thunderstone/medias.txt","w+b");                                
       fputs(buffer, nlenF);
       printf("\n共写入数据=%ld\n",strlen(buffer));
       fclose(nlenF );
       printf("\n创建媒体\n");
       Num=9000001;
       for(destnation=1;destnation       {
        memset(maxFileNamee,0,100); 
        sprintf(maxFileNamee,"touch /thunderstone/medias/%d.mpg",Num++);
        system(maxFileNamee);
      }
       return 0;
      }
 else
  return 0; 
}

阅读(3815) | 评论(0) | 转发(0) |
0

上一篇:查看CPU及内存信息

下一篇:system

给主人留下些什么吧!~~