| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1152 人关注过本帖
标题:关于用VC写控制台程序的几个小疑问?
只看楼主 加入收藏
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
结帖率:97.66%
收藏
已结贴  问题点数:20 回复次数:18 
关于用VC写控制台程序的几个小疑问?
求高手~VC写控制台程序~
1.能用API吗?有跟MFC一样内建吗?
2.搜寻特定资料夹下的特定相似档案要怎写?
3.档案全路径怎切割为档案路径和档名?
4.这用VB写超简单~纯C我就头大了~又没CString的这个类能用~全都要用指针和双指针去实现~好烦~

P.S 档案是由参数带入的~所以事先无法得知~

int main(int argc, char* argv[])
{
    ......
    //argc=3;argv[0]="AAA.exe";argv[1]="3";argv[2]="C:\\111\\222\\333_4444_555_6666666_77_88_120215180213.txt"
    //0:执行档名称 1:选择参数 2:档案路径
}

这只是一小部分~后面还一大串~
搜索更多相关主题的帖子: 切割 控制台 资料 
2012-02-16 19:46
闲出屁
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:7
帖 子:420
专家分:612
注 册:2012-1-24
收藏
得分:20 
1.可以建MFC控制台工程
2.百度找API 然后自己写比对
3.MSDN: _splitpath
4.同1 不行就用std::string

乔布斯是神 宫崎骏也是神~~ 才知道 原来士兵突击的主题曲是久石让的 久石让的音乐 真传神
2012-02-16 19:50
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
那有不用CString的的做法吗?

不要選我當版主
2012-02-16 20:08
闲出屁
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:7
帖 子:420
专家分:612
注 册:2012-1-24
收藏
得分:0 
char*呗

乔布斯是神 宫崎骏也是神~~ 才知道 原来士兵突击的主题曲是久石让的 久石让的音乐 真传神
2012-02-16 20:12
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
比这种简单的纯C写法?
程序代码:
//------------------------------------------------------------------------------------------------------------------//
int main(int argc, char* argv[])
{
    int i=0, j=0, k=0, len=0, opt=0;
    char *ex, *config=0;
    char FN[256];
    char PathArr[256];
    char FilePath[256]={0};
    char wFilePath[256]={0};
    char eFilePath[256]={0};
    char FileName[1024]={0};
    
  //time_t ltime;
    char cpDate[25]={0};
    char cpTime[25]={0};
    char cpFilename[50]={0};
   //time( &ltime );
    
    argc=3;argv[1]="3";argv[2]="C:\\STDF\\33\\AAA_BBBBBB_CCC_DDDDD_00_02_120215180213.std";

    opt=atoi(argv[1]);        //因為0:執行檔名稱 1:選擇參數 2:檔案路徑

    _strtime( cpTime );
    _strdate( cpDate );
    
    strncpy(cpFilename, cpDate+6,2);
    strncpy(cpFilename+2, cpDate,2);
    strncpy(cpFilename+4, cpDate+3,2);
    strncpy(cpFilename+6, cpTime,2);
    strncpy(cpFilename+8, cpTime+3,2);
    strncpy(cpFilename+10, cpTime+6,2);
    time_t unixtime=0;
    time(&unixtime);

    strcpy(PathArr, argv[2]);
    printf("\nThe Path is %d: %s\n\n",opt,PathArr);
    printf("1:STDF Transform ATDF.\n2:ATDF Transform STDF(No Finish).\n3:STDF Merge STDF.\n4.ATDF Merge ATDF(No Finish).\n");
    strcpy(FN,PathArr);
    ex=strrchr(PathArr,'.');

    int nIndex =strlen(PathArr) -sizeof ("100603194915.std");
      
      PathArr[nIndex +1] ='*';
      PathArr[nIndex +2] ='.';
      PathArr[nIndex +3] ='s';
      PathArr[nIndex +4] ='t';
      PathArr[nIndex +5] ='d';
      PathArr[nIndex +6] ='\0';

      for(i=0;i<sizeof(PathArr);i++)
      {
           if (PathArr[i]=='\\')
            j=i;
      }
      for(i=sizeof(PathArr);i>=0;i--)
      {
           if (PathArr[i]=='\0')
            k=i;
      }
      
      memcpy( FilePath, PathArr, j+1 );
      strncpy( FileName,PathArr+j+1,k-j );
      nIndex =strlen(FileName);
      FileName[nIndex -5] ='\0';
      strcat(FileName,cpFilename);
      memcpy(wFilePath, FilePath, strlen(FilePath));
      nIndex =strlen(wFilePath);
      wFilePath[nIndex ] ='T';
      wFilePath[nIndex +1] ='r';
      wFilePath[nIndex +2] ='a';
      wFilePath[nIndex +3] ='n';
      wFilePath[nIndex +4] ='s';
      wFilePath[nIndex +5] ='f';
      wFilePath[nIndex +6] ='o';
      wFilePath[nIndex +7] ='r';
      wFilePath[nIndex +8] ='m';
      wFilePath[nIndex +9] ='\\';
      
      if( (_access(wFilePath, 0 )) == -1 ) 
        int intRet = (_mkdir(wFilePath));

      strcat(wFilePath,FileName);
      strcpy(eFilePath, wFilePath);
      nIndex =strlen(wFilePath);
      wFilePath[nIndex ] ='.';
      wFilePath[nIndex +1] ='a';
      wFilePath[nIndex +2] ='t';
      wFilePath[nIndex +3] ='d';
      wFilePath[nIndex +4] ='f';
      wFilePath[nIndex +5] ='\0';

      nIndex =strlen(eFilePath);
      eFilePath[nIndex ] ='.';
      eFilePath[nIndex +1] ='l';
      eFilePath[nIndex +2] ='o';
      eFilePath[nIndex +3] ='g';
      eFilePath[nIndex +4] ='\0';
      
      len=strlen(ex);

      if((opt==1)&&(len==4))
            ST2AT(1,FN,wFilePath,eFilePath);
      else if((opt==2)&&(len==5))
            AT2ST(2,FN,wFilePath,eFilePath);
      else if((opt==3)&&(len==4))
            ST2MG(3,FN,wFilePath,eFilePath);
      else if((opt==4)&&(len==5))
            AT2MG(4,FN,wFilePath,eFilePath);
      else
            printf("opt Number Input Error!");

      printf("Work Finish !!!");

    //system("pause");
    return 0;
}

不要選我當版主
2012-02-16 20:13
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
后面还有数千行要全贴吗?

不要選我當版主
2012-02-16 20:15
闲出屁
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:7
帖 子:420
专家分:612
注 册:2012-1-24
收藏
得分:0 
关键没明白你要干嘛

乔布斯是神 宫崎骏也是神~~ 才知道 原来士兵突击的主题曲是久石让的 久石让的音乐 真传神
2012-02-16 21:14
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册

刚好不容易在Win 7 64位的操作系统下装了VS6.0~试了一下_splitpath能用的~
这样光撷取路径和档名就少了好多行代码了~
超感谢~

不过还一个问题~
找档案夹下的相似档案列表清单~批次处理~这要怎做?

我在VB都是用Microsoft Scripting RunTime + for each + instr 运行~但是在C就不清楚了~
有简单点的吗?谢谢~

不要選我當版主
2012-02-16 22:05
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
找档案夹下的相似档案列表清单~
有清单我会写批次处理~
重点是我不会用C找档案夹下的相似档案列表清单~

不要選我當版主
2012-02-16 22:30
闲出屁
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:7
帖 子:420
专家分:612
注 册:2012-1-24
收藏
得分:0 
直接相似我也不懂 就会找文件 搜VC 文件目录 应该能搜到很多 然后再去找MSDN就应该轻松搞出来
至于你那相似 我还是不太懂 应该需要自己写算法吧 vb的foreach也只是列出清单来吧 instr是什么不清楚

乔布斯是神 宫崎骏也是神~~ 才知道 原来士兵突击的主题曲是久石让的 久石让的音乐 真传神
2012-02-16 22:55
快速回复:关于用VC写控制台程序的几个小疑问?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034980 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved